Blog

How to configure an AWS Global Accelerator in CloudFormation

10 Jul, 2019
Xebia Background Header Wave

On May 14th 2020, AWS announced availability of CloudFormation support for AWS Global Accelerator.

In this blog we show you how to configure your accelerators, listeners and endpoint groups in CloudFormation using the new resources.

how do I configure it?

First, you have to add the AWS::GlobalAccelerator::Accelerator and a AWS::GlobalAccelerator::Listener to your CloudFormation template.

Resources:
  Accelerator:
    Type: AWS::GlobalAccelerator::Accelerator
    Properties:
      Name: !Sub '${AWS::StackName}'
      Enabled: true
      IpAddressType: IPV4

  Listener:
    Type: AWS::GlobalAccelerator::Listener
    Properties:
      AcceleratorArn: !Ref Accelerator
      Protocol: TCP
      PortRanges:
        - FromPort: 80
          ToPort: 80
      ClientAffinity: NONE

In this demo we deploy our application in eu-west-1 and eu-central-1 using Fargate, and front it with a load balancer. The Load Balancer is added to the Endpoint group, which in turn is connected to the global load balancer listener.

  EndpointGroup:
    Type: AWS::GlobalAccelerator::EndpointGroup
    Properties:
      ListenerArn: !Ref GlobalAcceleratorListener
      TrafficDialPercentage: !Ref TrafficPercentage
      EndpointGroupRegion: !Ref AWS::Region
      EndpointConfigurations:
        - EndpointId: !Ref LoadBalancer
          Weight: 100

  LoadBalancer:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Subnets: !Ref PublicSubnets
      SecurityGroups:
      - !Ref ALBSecurityGroup

Demo

The following tree shows the deployment configuration of our global accelerator demo:

demo
└── us-west-2
    ├── accelerator.yaml
├── eu-central-1
│   ├── app.yaml
│   └── vpc.yaml
├── eu-west-1
│   ├── app.yaml
│   └── vpc.yaml

The accelerator is deployed in us-west-2 and the application is deployed in both eu-central-1 and eu-west-1 respectively.

Deploy the demo

In order to deploy the demo, type:

git clone https://github.com/binxio/blog-how-to-configure-an-aws-global-accelerator-in-cloudformation.git
cd blog-how-to-configure-an-aws-global-accelerator-in-cloudformation
pip install sceptre
sceptre launch -y demo

to view the application, type:`

DNS_NAME=$(
  aws --region us-west-2 globalaccelerator 
  list-accelerators 
    --output text 
    --query 'Accelerators[?Name==<code>cfn-global-accelerator-demo-us-west-2-accelerator].DnsName')

open http://$DNS_NAME

Conclusion

With the new AWS CloudFormation resources you can configure the Global Accelerator to improve the availability and performance of your applications with local or global users.

If you are using terraform, checkout building a global application with AWS Global Accelerator using terraform.

Image by WikiImages from Pixabay

Mark van Holsteijn
Mark van Holsteijn is a senior software systems architect at Xebia Cloud-native solutions. He is passionate about removing waste in the software delivery process and keeping things clear and simple.
Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts