Skip to main content

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.

Remarks

The project is written by Laimonas Sutkus and is owned by iDenfy. This is an open source library intended to be used by anyone. iDenfy aims to share its knowledge and educate market for better and more secure IT infrastructure.

This project utilizes the following technology:

  • AWS (Amazon Web Services).
  • AWS CDK (Amazon Web Services Cloud Development Kit).
  • AWS CloudFormation.
  • AWS Loadbalancer.
  • AWS Security groups.

Assumptions

This 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.

Install

The project is built and uploaded to PyPi. Install it by using pip.

pip install aws-alb

Or directly install it through source.

./build.sh -ic

Description

It 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.

Examples

To create an application loadbalancer create an ApplicationLoadbalancer instance in your stack. An example is given below:

from aws_cdk import core, aws_ec2
from aws_alb.application_loadbalancer import ApplicationLoadbalancer

class MainStack(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:

from aws_alb.params.listener_params import ListenerParams
from aws_alb.params.target_group_params import TargetGroupParams
from aws_alb.application_loadbalancer import ApplicationLoadbalancer
from aws_cdk.aws_ec2 import Vpc

loadbalancer = 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 = blue
green_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:

from aws_alb.application_loadbalancer import ApplicationLoadbalancer
from aws_cdk.aws_certificatemanager import CfnCertificate
from aws_cdk.aws_ec2 import Vpc

loadbalancer = 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 history

4.3.0

Force CDK version update to 1.60.0 and add a limit of 2.0.0.

4.2.0

Force CDK version update to 1.44.0.

4.1.1

Bug fixes.

4.1.0

Add ability to specify inbound and outbound traffic.

4.0.1

Bug fixes.

4.0.0

Bug fixes and even prettier and more convenient code.

3.0.0

Better blue-green integration. Support for default blue-green listeners.

2.0.1

Readme update.

2.0.0

Complete 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.2

Renames.

1.0.1

Bug fix.

1.0.0

Initial project.

Metadata

Release files for aws-alb 4.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-alb 4.3.0
File Size Uploaded Provenance Actions
aws_alb-4.3.0.tar.gz 10.0 kB Without provenance Details for aws_alb-4.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aws-alb 4.3.0
File Interpreter ABI Platform Actions
aws_alb-4.3.0-py3-none-any.whl Python 3 none any Details for aws_alb-4.3.0-py3-none-any.whl

Total release size: 34.8 kB

Release files / aws_alb-4.3.0.tar.gz

Download URL aws_alb-4.3.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a6461a34df99af7d9e9342c1cf4b4e2eed812cff66f7816d9cfefee147f46d37
BLAKE2b-256 checksum
How to use checksums
2ac1dd3340a8e326deb3a80c63f6562b4cd1ada2f6fcb94744d4b25edb8ac3d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

Release files / aws_alb-4.3.0-py3-none-any.whl

Download URL aws_alb-4.3.0-py3-none-any.whl
Size 24.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72753afd3161ac44747054b84df6a589313819905989bd9f03ddd40e091a8884
BLAKE2b-256 checksum
How to use checksums
e28f1f221024e90ef8a96a42c44988a4421b16a97d24b006147ccfc4f655ff55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

Security for aws-alb 4.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page