Package software.amazon.awscdk.services.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 the Migrating to AWS CDK v2 guide.
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 accelerator = new Accelerator(this, "Accelerator");
// Create a Listener
Listener listener = accelerator.addListener("Listener", ListenerOptions.builder()
.portRanges(List.of(PortRange.builder().fromPort(80).build(), PortRange.builder().fromPort(443).build()))
.build());
// Import the Load Balancers
INetworkLoadBalancer nlb1 = NetworkLoadBalancer.fromNetworkLoadBalancerAttributes(this, "NLB1", NetworkLoadBalancerAttributes.builder()
.loadBalancerArn("arn:aws:elasticloadbalancing:us-west-2:111111111111:loadbalancer/app/my-load-balancer1/e16bef66805b")
.build());
INetworkLoadBalancer nlb2 = NetworkLoadBalancer.fromNetworkLoadBalancerAttributes(this, "NLB2", NetworkLoadBalancerAttributes.builder()
.loadBalancerArn("arn:aws:elasticloadbalancing:ap-south-1:111111111111:loadbalancer/app/my-load-balancer2/5513dc2ea8a1")
.build());
// Add one EndpointGroup for each Region we are targeting
listener.addEndpointGroup("Group1", EndpointGroupOptions.builder()
.endpoints(List.of(new NetworkLoadBalancerEndpoint(nlb1)))
.build());
listener.addEndpointGroup("Group2", EndpointGroupOptions.builder()
// 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(List.of(new NetworkLoadBalancerEndpoint(nlb2)))
.build());
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
ApplicationLoadBalancer alb;
Listener listener;
listener.addEndpointGroup("Group", EndpointGroupOptions.builder()
.endpoints(List.of(
ApplicationLoadBalancerEndpoint.Builder.create(alb)
.weight(128)
.preserveClientIp(true)
.build()))
.build());
Network Load Balancers
NetworkLoadBalancer nlb;
Listener listener;
listener.addEndpointGroup("Group", EndpointGroupOptions.builder()
.endpoints(List.of(
NetworkLoadBalancerEndpoint.Builder.create(nlb)
.weight(128)
.build()))
.build());
EC2 Instances
Listener listener;
Instance instance;
listener.addEndpointGroup("Group", EndpointGroupOptions.builder()
.endpoints(List.of(
InstanceEndpoint.Builder.create(instance)
.weight(128)
.preserveClientIp(true)
.build()))
.build());
Elastic IP Addresses
Listener listener;
CfnEIP eip;
listener.addEndpointGroup("Group", EndpointGroupOptions.builder()
.endpoints(List.of(
CfnEipEndpoint.Builder.create(eip)
.weight(128)
.build()))
.build());
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:
Listener listener;
// Non-open ALB
ApplicationLoadBalancer alb;
// Remember that there is only one AGA security group per VPC.
Vpc vpc;
EndpointGroup endpointGroup = listener.addEndpointGroup("Group", EndpointGroupOptions.builder()
.endpoints(List.of(
ApplicationLoadBalancerEndpoint.Builder.create(alb)
.preserveClientIp(true)
.build()))
.build());
IPeer agaSg = endpointGroup.connectionsPeer("GlobalAcceleratorSG", vpc);
// Allow connections from the AGA to the ALB
alb.connections.allowFrom(agaSg, Port.tcp(443));
Deprecated: 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 https://docs.aws.amazon.com/cdk/v2/guide/migrating-v2.html-
ClassDescriptionThe Accelerator construct.A fluent builder for
Accelerator.Attributes required to import an existing accelerator to the stack.A builder forAcceleratorAttributesAn implementation forAcceleratorAttributesConstruct properties of the Accelerator.A builder forAcceleratorPropsAn implementation forAcceleratorPropsA CloudFormationAWS::GlobalAccelerator::Accelerator.A fluent builder forCfnAccelerator.Properties for defining aCfnAccelerator.A builder forCfnAcceleratorPropsAn implementation forCfnAcceleratorPropsA CloudFormationAWS::GlobalAccelerator::EndpointGroup.A fluent builder forCfnEndpointGroup.A complex type for endpoints.A builder forCfnEndpointGroup.EndpointConfigurationPropertyAn implementation forCfnEndpointGroup.EndpointConfigurationPropertyOverride specific listener ports used to route traffic to endpoints that are part of an endpoint group.A builder forCfnEndpointGroup.PortOverridePropertyAn implementation forCfnEndpointGroup.PortOverridePropertyProperties for defining aCfnEndpointGroup.A builder forCfnEndpointGroupPropsAn implementation forCfnEndpointGroupPropsA CloudFormationAWS::GlobalAccelerator::Listener.A fluent builder forCfnListener.A complex type for a range of ports for a listener.A builder forCfnListener.PortRangePropertyAn implementation forCfnListener.PortRangePropertyProperties for defining aCfnListener.A builder forCfnListenerPropsAn implementation forCfnListenerPropsClient affinity gives you control over whether to always route each client to the same specific endpoint.The protocol for the connections from clients to the accelerator.EndpointGroup construct.A fluent builder forEndpointGroup.Basic options for creating a new EndpointGroup.A builder forEndpointGroupOptionsAn implementation forEndpointGroupOptionsProperty of the EndpointGroup.A builder forEndpointGroupPropsAn implementation forEndpointGroupPropsThe protocol for the connections from clients to the accelerator.The interface of the Accelerator.Internal default implementation forIAccelerator.A proxy class which represents a concrete javascript instance of this type.An endpoint for the endpoint group.Internal default implementation forIEndpoint.A proxy class which represents a concrete javascript instance of this type.The interface of the EndpointGroup.Internal default implementation forIEndpointGroup.A proxy class which represents a concrete javascript instance of this type.Interface of the Listener.Internal default implementation forIListener.A proxy class which represents a concrete javascript instance of this type.The construct for the Listener.A fluent builder forListener.Construct options for Listener.A builder forListenerOptionsAn implementation forListenerOptionsConstruct properties for Listener.A builder forListenerPropsAn implementation forListenerPropsOverride specific listener ports used to route traffic to endpoints that are part of an endpoint group.A builder forPortOverrideAn implementation forPortOverrideThe list of port ranges for the connections from clients to the accelerator.A builder forPortRangeAn implementation forPortRangeUntyped endpoint implementation.A fluent builder forRawEndpoint.Properties for RawEndpoint.A builder forRawEndpointPropsAn implementation forRawEndpointProps