Go Global with AWS - Use AWS CloudFormation StackSets to go global with ease

jonholman_

Jon Holman

Posted on April 7, 2022

Go Global with AWS - Use AWS CloudFormation StackSets to go global with ease

I have wanted to create a multi-region, global application with AWS to see how much effort it would be. I finally took some time to create a simple proof of concept, and I am amazed by how easy it was, thanks to CloudFormation StackSets. CloudFormation StackSets makes deploying the same stack to multiple regions and accounts easy. AWS CDK, AWS SAM, AWS CloudFormation, and I'm sure many other IaC tools can create CloudFormation StackSets. To keep this proof of concept small and straightforward, I used AWS SAM to simplify the creation of the CloudFormation resources for AWS Lambda with Amazon API Gateway in the regional deployments. These concepts can easily be applied to a more robust application to deploy across multiple accounts and regions.

To begin, I created a simple single-region template using AWS SAM and its CLI while I worked on that. With the lambda function's code inline within the template. Once I had the per region template the way I wanted, I moved that template to be nested within a CloudFormation StackSet. I would have preferred to be able to keep the nested template as YAML. Supplying YAML for the StackSet's TemplateBody attributed resulted in the error message 'expected type: String, found: JSONObject.' It wanted a string, so I put a | after TemplateBody, which converted the YAML indented below into a multiline string. This sample leverages 16 AWS regions. The last time I ran it, it completed deployment in 18 minutes.

This simple proof of concept only has one file, template.yaml, available in the GitHub gist below with instructions to deploy and remove beneath it.

To deploy this sample application, you need:

  • An AWS Account
  • A Route53 hosted zone in the AWS account you are using
  • Then to deploy, you can use any of these:

To deploy your application for the first time.

Run the following in your shell (replace <domain_name> and <route_53_zone_id> for your environment):

For the AWS CLI:

aws cloudformation create-stack --region us-east-1 --stack-name multi-region-sam-poc --template-body file://template.yaml --capabilities CAPABILITY_NAMED_IAM --parameters ParameterKey=DomainName,ParameterValue=<domain_name> ParameterKey=Route53ZoneId,ParameterValue=<route_53_zone_id>

For the AWS SAM CLI:

sam deploy --guided

To delete the sample application that you created.

For the AWS CLI:

aws cloudformation delete-stack --region us-east-1 --stack-name multi-region-sam-poc

For the AWS SAM CLI:

sam delete

Thanks for reading. If you have any questions or feedback, please leave a comment or message me on Twitter, link to the right.

💖 💪 🙅 🚩
jonholman_
Jon Holman

Posted on April 7, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related