Package: aws-cdk.aws-globalaccelerator
AWS::GlobalAccelerator Construct Library---AWS CDK v1 has reached End-of-Support on 2023-06-01.
This package is no longer being updated, and users should migrate to AWS CDK v2.For more information on how to migrate, see theMigrating to AWS CDK v2guide.IntroductionAWS 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 theAWS Global
Accelerator Developer Guide.ExampleHere's an example that sets up a Global Accelerator for two Application Load
Balancers in two different AWS Regions:# Create an Acceleratoraccelerator=globalaccelerator.Accelerator(self,"Accelerator")# Create a Listenerlistener=accelerator.add_listener("Listener",port_ranges=[globalaccelerator.PortRange(from_port=80),globalaccelerator.PortRange(from_port=443)])# Import the Load Balancersnlb1=elbv2.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=elbv2.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 targetinglistener.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)])ConceptsTheAcceleratorconstruct defines a Global Accelerator resource.An Accelerator includes one or moreListenersthat accepts inbound
connections on one or more ports.Each Listener has one or moreEndpoint 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 moreEndpoints, 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 EndpointsThere are 4 types of Endpoints, and they can be found in the@aws-cdk/aws-globalaccelerator-endpointspackage:Application Load BalancersNetwork Load BalancersEC2 InstancesElastic IP AddressesApplication Load Balancers# alb: elbv2.ApplicationLoadBalancer# listener: globalaccelerator.Listenerlistener.add_endpoint_group("Group",endpoints=[ga_endpoints.ApplicationLoadBalancerEndpoint(alb,weight=128,preserve_client_ip=True)])Network Load Balancers# nlb: elbv2.NetworkLoadBalancer# listener: globalaccelerator.Listenerlistener.add_endpoint_group("Group",endpoints=[ga_endpoints.NetworkLoadBalancerEndpoint(nlb,weight=128)])EC2 Instances# listener: globalaccelerator.Listener# instance: ec2.Instancelistener.add_endpoint_group("Group",endpoints=[ga_endpoints.InstanceEndpoint(instance,weight=128,preserve_client_ip=True)])Elastic IP Addresses# listener: globalaccelerator.Listener# eip: ec2.CfnEIPlistener.add_endpoint_group("Group",endpoints=[ga_endpoints.CfnEipEndpoint(eip,weight=128)])Client IP Address Preservation and Security GroupsWhen using thepreserveClientIpfeature, AGA createsElastic 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 calledGlobalAcceleratorfor 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.CallendpointGroup.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: globalaccelerator.Listener# Non-open ALB# alb: elbv2.ApplicationLoadBalancer# Remember that there is only one AGA security group per VPC.# vpc: ec2.Vpcendpoint_group=listener.add_endpoint_group("Group",endpoints=[ga_endpoints.ApplicationLoadBalancerEndpoint(alb,preserve_client_ip=True)])aga_sg=endpoint_group.connections_peer("GlobalAcceleratorSG",vpc)# Allow connections from the AGA to the ALBalb.connections.allow_from(aga_sg,ec2.Port.tcp(443))