Package: aws-alb
AWS ALB (Application Load Balancer)An abstract application loadbalancer construct. It creates a loadbalancer and default
security groups and listeners for the loadbalancer. Also, this loadbalancer is ready
for blue-green deployments.RemarksThe project is written byLaimonas Sutkusand is owned byiDenfy. This is an open source
library intended to be used by anyone.iDenfyaims
to share its knowledge and educate market for better and more secure IT infrastructure.Related technologyThis project utilizes the following technology:AWS(Amazon Web Services).AWS CDK(Amazon Web Services Cloud Development Kit).AWS CloudFormation.AWS Loadbalancer.AWS Security groups.AssumptionsThis library project assumes the following:You have knowledge in AWS (Amazon Web Services).You have knowledge in AWS CloudFormation and AWS loadbalancing.You are managing your infrastructure with AWS CDK.You are writing AWS CDK templates with a python language.InstallThe project is built and uploaded to PyPi. Install it by using pip.pipinstallaws-albOr directly install it through source../build.sh-icDescriptionIt is usually hard to create a loadbalancer following best practices and rules. Also, most of the
time the deployed loadbalancer will lack some configuration functionality for deployment management.
We tackle these problems by providing you a library to easily deploy and maintain a loadbalancer with
right security groups, right listeners and most importantly right configuration for blue-green deployments.ExamplesTo create an application loadbalancer create anApplicationLoadbalancerinstance in your stack. An example is given below:fromaws_cdkimportcore,aws_ec2fromaws_alb.application_loadbalancerimportApplicationLoadbalancerclassMainStack(core.Stack):def__init__(self,scope:core.App)->None:super().__init__(scope=scope,id='MyCoolStack')# Create your own vpc.self.vpc=aws_ec2.Vpc(self,'MyCoolVpc')self.public_http_loadbalancer=ApplicationLoadbalancer(scope=self,prefix='MyCool',vpc=self.vpc,loadbalancer_subnets=self.vpc.public_subnets,security_groups=None,)To create listeners and target groups that are blue-green deployments ready:fromaws_alb.params.listener_paramsimportListenerParamsfromaws_alb.params.target_group_paramsimportTargetGroupParamsfromaws_alb.application_loadbalancerimportApplicationLoadbalancerfromaws_cdk.aws_ec2importVpcloadbalancer=ApplicationLoadbalancer(...)vpc=Vpc(...)blue,green=loadbalancer.listeners.create_blue_green(blue_listener_params=ListenerParams(prefix='MyCool',loadbalancer=loadbalancer,port=80),green_listener_params=ListenerParams(prefix='MyCool',loadbalancer=loadbalancer.loadbalancer,port=8000),blue_target_group_params=TargetGroupParams(prefix='MyCool',vpc=vpc,),green_target_group_params=TargetGroupParams(prefix='MyCool',vpc=vpc,))# If you need, you can access created target groups and listeners.blue_target_group,blue_listener=bluegreen_target_group,green_listener=green# To see to which ports listeners are listening to:print(blue_listener.port)print(green_listener.port)Usually, it is the best practice to have one loadbalancer with two (http
and https) listeners and have listener rules to route traffic. To create
default listeners:fromaws_alb.application_loadbalancerimportApplicationLoadbalancerfromaws_cdk.aws_certificatemanagerimportCfnCertificatefromaws_cdk.aws_ec2importVpcloadbalancer=ApplicationLoadbalancer(...)vpc=Vpc(...)cert=CfnCertificate(...)blue,green=loadbalancer.listeners.create_default_listeners(prefix='MyCool',loadbalancer=loadbalancer.loadbalancer,certificate=cert)print(blue.port)# Should be 443.print(green.port)# Should be 44300.Release history4.3.0Force CDK version update to 1.60.0 and add a limit of 2.0.0.4.2.0Force CDK version update to 1.44.0.4.1.1Bug fixes.4.1.0Add ability to specify inbound and outbound traffic.4.0.1Bug fixes.4.0.0Bug fixes and even prettier and more convenient code.3.0.0Better blue-green integration. Support for default blue-green listeners.2.0.1Readme update.2.0.0Complete refactor. Instead of creating default listeners add an ability to create custom listeners and
target groups. The loadbalancer now exposes an explicit method to easily create a pair of listeners and
a pair of target groups for easy out-of-the-box blue/green deployment configuration.1.0.2Renames.1.0.1Bug fix.1.0.0Initial project.