AWS CDK Global Accelerator

1.204.0 · active · verified Fri Apr 17

The AWS Cloud Development Kit (CDK) Construct Library for AWS Global Accelerator. This library allows developers to define and provision Global Accelerator resources using familiar programming languages. It is part of the AWS CDK v1 ecosystem, with version 1.204.0 being released as part of the broader CDK v1 maintenance cycle. AWS CDK has a regular release cadence, often weekly for minor updates and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic Global Accelerator with a listener and an empty endpoint group. It's runnable and will synthesize a CloudFormation template. To make it functional, you would typically add actual application endpoints (like Application Load Balancers or EC2 instances) to the `endpoint_group`.

import os
from aws_cdk import (
    core as cdk,
    aws_globalaccelerator as ga
)

class GlobalAcceleratorStack(cdk.Stack):
    def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # Create a Global Accelerator
        accelerator = ga.Accelerator(self, "MyGlobalAccelerator",
            accelerator_name="MyWebAppAccelerator"
        )

        # Add a Listener for HTTP traffic on port 80
        # GA listeners are always TCP or UDP. HTTP/S is handled by the endpoints.
        listener = ga.Listener(self, "HttpListener",
            accelerator=accelerator,
            port_ranges=[ga.PortRange(from_port=80, to_port=80)],
            protocol=ga.ConnectionProtocol.TCP
        )

        # Add an Endpoint Group for a specific region
        # This group is initially empty; you would add actual endpoints to it.
        endpoint_group = ga.EndpointGroup(self, "UsEast1EndpointGroup",
            listener=listener,
            endpoint_group_region="us-east-1" # The region where your application endpoints reside
        )

        # To add actual endpoints (e.g., an Application Load Balancer):
        # from aws_cdk import aws_globalaccelerator_endpoints as ga_endpoints
        # from aws_cdk import aws_elasticloadbalancingv2 as elbv2
        # alb = elbv2.ApplicationLoadBalancer.from_lookup(...)
        # endpoint_group.add_endpoint(ga_endpoints.ApplicationLoadBalancerEndpoint(alb))

app = cdk.App()
GlobalAcceleratorStack(app, "GlobalAcceleratorQuickstartStack",
    env=cdk.Environment(
        account=os.environ.get("CDK_DEFAULT_ACCOUNT"),
        region=os.environ.get("CDK_DEFAULT_REGION", "us-east-1") # GA itself is global, but stack needs a region for deployment
    )
)
app.synth()

view raw JSON →