AWSCDK::GlobalAccelerator

29 types

AWS::GlobalAccelerator Construct Library

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:

# Create an Accelerator
accelerator = AWSCDK::GlobalAccelerator::Accelerator.new(self, "Accelerator")

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

# Import the Load Balancers
nlb1 = AWSCDK::ElasticLoadBalancingv2::NetworkLoadBalancer.from_network_load_balancer_attributes(self, "NLB1", {
    load_balancer_arn: "arn:aws:elasticloadbalancing:us-west-2:111111111111:loadbalancer/app/my-load-balancer1/e16bef66805b",
})
nlb2 = AWSCDK::ElasticLoadBalancingv2::NetworkLoadBalancer.from_network_load_balancer_attributes(self, "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: [AWSCDK::GlobalAcceleratorEndpoints::NetworkLoadBalancerEndpoint.new(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: [AWSCDK::GlobalAcceleratorEndpoints::NetworkLoadBalancerEndpoint.new(nlb2)],
})

Create an Accelerator with IP addresses and IP address type

accelerator = AWSCDK::GlobalAccelerator::Accelerator.new(self, "Accelerator", {
    ip_addresses: [
        "1.1.1.1",
        "2.2.2.2",
    ],
    ip_address_type: AWSCDK::GlobalAccelerator::IPAddressType::IPV4,
})

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-lib/aws-globalaccelerator-endpoints package:

Application Load Balancers

alb = nil # AWSCDK::ElasticLoadBalancingv2::ApplicationLoadBalancer
listener = nil # AWSCDK::GlobalAccelerator::Listener


listener.add_endpoint_group("Group", {
    endpoints: [
        AWSCDK::GlobalAcceleratorEndpoints::ApplicationLoadBalancerEndpoint.new(alb, {
            weight: 128,
            preserve_client_ip: true,
        }),
    ],
})

Network Load Balancers

nlb = nil # AWSCDK::ElasticLoadBalancingv2::NetworkLoadBalancer
listener = nil # AWSCDK::GlobalAccelerator::Listener


listener.add_endpoint_group("Group", {
    endpoints: [
        AWSCDK::GlobalAcceleratorEndpoints::NetworkLoadBalancerEndpoint.new(nlb, {
            weight: 128,
            preserve_client_ip: true,
        }),
    ],
})

EC2 Instances

listener = nil # AWSCDK::GlobalAccelerator::Listener
instance = nil # AWSCDK::EC2::Instance


listener.add_endpoint_group("Group", {
    endpoints: [
        AWSCDK::GlobalAcceleratorEndpoints::InstanceEndpoint.new(instance, {
            weight: 128,
            preserve_client_ip: true,
        }),
    ],
})

Elastic IP Addresses

listener = nil # AWSCDK::GlobalAccelerator::Listener
eip = nil # AWSCDK::EC2::CfnEIP


listener.add_endpoint_group("Group", {
    endpoints: [
        AWSCDK::GlobalAcceleratorEndpoints::CfnEipEndpoint.new(eip, {
            weight: 128,
        }),
    ],
})

Client IP Address Preservation and Security Groups

When using the preserve_client_ip 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:

listener = nil # AWSCDK::GlobalAccelerator::Listener

# Non-open ALB
alb = nil # AWSCDK::ElasticLoadBalancingv2::ApplicationLoadBalancer

# Remember that there is only one AGA security group per VPC.
vpc = nil # AWSCDK::EC2::VPC


endpoint_group = listener.add_endpoint_group("Group", {
    endpoints: [
        AWSCDK::GlobalAcceleratorEndpoints::ApplicationLoadBalancerEndpoint.new(alb, {
            preserve_client_ip: true,
        }),
    ],
})
aga_sg = endpoint_group.connections_peer("GlobalAcceleratorSG", vpc)

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

API Reference

Classes 8

AcceleratorThe Accelerator construct. CfnAcceleratorThe `AWS::GlobalAccelerator::Accelerator` resource is a Global Accelerator resource type t CfnCrossAccountAttachmentCreate a cross-account attachment in AWS Global Accelerator . CfnEndpointGroupThe `AWS::GlobalAccelerator::EndpointGroup` resource is a Global Accelerator resource type CfnListenerThe `AWS::GlobalAccelerator::Listener` resource is a Global Accelerator resource type that EndpointGroupEndpointGroup construct. ListenerThe construct for the Listener. RawEndpointUntyped endpoint implementation.

Interfaces 17

AcceleratorAttributesAttributes required to import an existing accelerator to the stack. AcceleratorPropsConstruct properties of the Accelerator. CfnAcceleratorPropsProperties for defining a `CfnAccelerator`. CfnCrossAccountAttachmentPropsProperties for defining a `CfnCrossAccountAttachment`. CfnEndpointGroupPropsProperties for defining a `CfnEndpointGroup`. CfnListenerPropsProperties for defining a `CfnListener`. EndpointGroupOptionsBasic options for creating a new EndpointGroup. EndpointGroupPropsProperty of the EndpointGroup. IAcceleratorThe interface of the Accelerator. IEndpointAn endpoint for the endpoint group. IEndpointGroupThe interface of the EndpointGroup. IListenerInterface of the Listener. ListenerOptionsConstruct options for Listener. ListenerPropsConstruct properties for Listener. PortOverrideOverride specific listener ports used to route traffic to endpoints that are part of an en PortRangeThe list of port ranges for the connections from clients to the accelerator. RawEndpointPropsProperties for RawEndpoint.

Enums 4

ClientAffinityClient affinity gives you control over whether to always route each client to the same spe ConnectionProtocolThe protocol for the connections from clients to the accelerator. HealthCheckProtocolThe protocol for the connections from clients to the accelerator. IPAddressTypeThe IP address type that an accelerator supports.