Skip to main content

The CDK Construct Library for AWS::GlobalAccelerator

Project description

AWS::GlobalAccelerator Construct Library

---

cfn-resources: Stable

cdk-constructs: Stable


Introduction

AWS Global Accelerator (AGA) is a service that improves the availability and performance of your applications with local or global users.

It intercepts your user's network connection at an edge location close to them, and routes it to one of potentially multiple, redundant backends across the more reliable and less congested AWS global network.

AGA can be used to route traffic to Application Load Balancers, Network Load Balancers, EC2 Instances and Elastic IP Addresses.

For more information, see the AWS Global Accelerator Developer Guide.

Example

Here's an example that sets up a Global Accelerator for two Application Load Balancers in two different AWS Regions:

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import aws_cdk.aws_globalaccelerator as globalaccelerator
import aws_cdk.aws_globalaccelerator_endpoints as ga_endpoints
import aws_cdk.aws_elasticloadbalancingv2 as elbv2

# Create an Accelerator
accelerator = globalaccelerator.Accelerator(stack, "Accelerator")

# Create a Listener
listener = accelerator.add_listener("Listener",
    port_ranges=[PortRange(from_port=80), PortRange(from_port=443)
    ]
)

# Import the Load Balancers
nlb1 = elbv2.NetworkLoadBalancer.from_network_load_balancer_attributes(stack, "NLB1",
    load_balancer_arn="arn:aws:elasticloadbalancing:us-west-2:111111111111:loadbalancer/app/my-load-balancer1/e16bef66805b"
)
nlb2 = elbv2.NetworkLoadBalancer.from_network_load_balancer_attributes(stack, "NLB2",
    load_balancer_arn="arn:aws:elasticloadbalancing:ap-south-1:111111111111:loadbalancer/app/my-load-balancer2/5513dc2ea8a1"
)

# Add one EndpointGroup for each Region we are targeting
listener.add_endpoint_group("Group1",
    endpoints=[ga_endpoints.NetworkLoadBalancerEndpoint(nlb1)]
)
listener.add_endpoint_group("Group2",
    # Imported load balancers automatically calculate their Region from the ARN.
    # If you are load balancing to other resources, you must also pass a `region`
    # parameter here.
    endpoints=[ga_endpoints.NetworkLoadBalancerEndpoint(nlb2)]
)

Concepts

The Accelerator construct defines a Global Accelerator resource.

An Accelerator includes one or more Listeners that accepts inbound connections on one or more ports.

Each Listener has one or more Endpoint Groups, representing multiple geographically distributed copies of your application. There is one Endpoint Group per Region, and user traffic is routed to the closest Region by default.

An Endpoint Group consists of one or more Endpoints, which is where the user traffic coming in on the Listener is ultimately sent. The Endpoint port used is the same as the traffic came in on at the Listener, unless overridden.

Types of Endpoints

There are 4 types of Endpoints, and they can be found in the @aws-cdk/aws-globalaccelerator-endpoints package:

  • Application Load Balancers
  • Network Load Balancers
  • EC2 Instances
  • Elastic IP Addresses

Application Load Balancers

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
alb = elbv2.ApplicationLoadBalancer(...)

listener.add_endpoint_group("Group",
    endpoints=[
        ga_endpoints.ApplicationLoadBalancerEndpoint(alb,
            weight=128,
            preserve_client_ip=True
        )
    ]
)

Network Load Balancers

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
nlb = elbv2.NetworkLoadBalancer(...)

listener.add_endpoint_group("Group",
    endpoints=[
        ga_endpoints.NetworkLoadBalancerEndpoint(nlb,
            weight=128
        )
    ]
)

EC2 Instances

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
instance = ec2.instance(...)

listener.add_endpoint_group("Group",
    endpoints=[
        ga_endpoints.InstanceEndpoint(instance,
            weight=128,
            preserve_client_ip=True
        )
    ]
)

Elastic IP Addresses

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
eip = ec2.CfnEIP(...)

listener.add_endpoint_group("Group",
    endpoints=[
        ga_endpoints.CfnEipEndpoint(eip,
            weight=128
        )
    ]
)

Client IP Address Preservation and Security Groups

When using the preserveClientIp feature, AGA creates Elastic Network Interfaces (ENIs) in your AWS account, that are associated with a Security Group AGA creates for you. You can use the security group created by AGA as a source group in other security groups (such as those for EC2 instances or Elastic Load Balancers), if you want to restrict incoming traffic to the AGA security group rules.

AGA creates a specific security group called GlobalAccelerator for each VPC it has an ENI in (this behavior can not be changed). CloudFormation doesn't support referencing the security group created by AGA, but this construct library comes with a custom resource that enables you to reference the AGA security group.

Call endpointGroup.connectionsPeer() to obtain a reference to the Security Group which you can use in connection rules. You must pass a reference to the VPC in whose context the security group will be looked up. Example:

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
# ...

# Non-open ALB
alb = elbv2.ApplicationLoadBalancer(stack, "ALB")

endpoint_group = listener.add_endpoint_group("Group",
    endpoints=[
        ga_endpoints.ApplicationLoadBalancerEndpoint(alb,
            preserve_client_ips=True
        )
    ]
)

# Remember that there is only one AGA security group per VPC.
aga_sg = endpoint_group.connections_peer("GlobalAcceleratorSG", vpc)

# Allow connections from the AGA to the ALB
alb.connections.allow_from(aga_sg, Port.tcp(443))

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws-cdk.aws-globalaccelerator-1.124.0.tar.gz (78.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_cdk.aws_globalaccelerator-1.124.0-py3-none-any.whl (78.0 kB view details)

Uploaded Python 3

File details

Details for the file aws-cdk.aws-globalaccelerator-1.124.0.tar.gz.

File metadata

  • Download URL: aws-cdk.aws-globalaccelerator-1.124.0.tar.gz
  • Upload date:
  • Size: 78.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.5

File hashes

Hashes for aws-cdk.aws-globalaccelerator-1.124.0.tar.gz
Algorithm Hash digest
SHA256 2017a9fcdc68758265b24d2f4ea2cf08045383eb951d22098d0c36fcf9bfc014
MD5 71d2e1f5673c156ae9de47385556d729
BLAKE2b-256 2b7642eaf1e7221f636e2e5ace21a54c40998a9e10d8b4b4da4e889f50312fbb

See more details on using hashes here.

File details

Details for the file aws_cdk.aws_globalaccelerator-1.124.0-py3-none-any.whl.

File metadata

  • Download URL: aws_cdk.aws_globalaccelerator-1.124.0-py3-none-any.whl
  • Upload date:
  • Size: 78.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.5

File hashes

Hashes for aws_cdk.aws_globalaccelerator-1.124.0-py3-none-any.whl
Algorithm Hash digest
SHA256 388a752609ea19f8276ab6fa1002d37131c1379992dda62789fa6677a4514b2f
MD5 1b4a07ecce67adee7fcae3116301874e
BLAKE2b-256 50c8bbfae28f805137dafa6949a79a0e5a37c97104838ff79bb6f80b0e243f4c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page