Using AWS CodePipeline for cross region CloudFormation deployments

Using AWS CodePipeline for cross region CloudFormation deployments

Infrastructure as a Code (IaaC) is the preferred way to deploy and operate AWS resources. However if your infrastructure spans multiple regions, deploying resources using CloudFormation can become challenging. The problem is more profound when the the resources need to be dynamically referenced between regions to allow the infrastructure to operate correctly.

As always in AWS there are many ways to overcome this challenge, like using CloudFormation custom resource with SSM Parameter store, Lambda or using AWS CDK to manage multi region deployment. In this post I will show how to use AWS CodePipeline to achieve this.

If you are new to CodePipeline I encourage you to learn about it by reading docs. I will specifically use CodePipeline Artifacts to pass output from one CloudFormation stack as input to the cross region CloudFormation Stack parameters.

In this example scenario, the API gateway and Lambda function needs to be deployed in Sydney region, however edge services WAFv2 ACL and CloudFront needs to be deployed from US Virginia region. While deploying CloudFront distribution from Virginia we need to pass the domain name of the API gateway deployed in Sydney region.

No alt text provided for this image

I have two CloudFormation templates, cf1.yml deploys API Gateway and Lambda, cf2.yml deploys CloudFront and WAF ACL and associates WAF ACL with CloudFront and sets CloudFront distribution origin as API Gateway domain.

CodePipeline is deployed in Sydney region and is triggered by upload of these templates (as a single zip) to S3 bucket (versioning enabled) in the Sydney region.

Lets go through the CodePipleine details in detail and see how this maps into the CloudFormation template outputs and parameters

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Edit the deploy stage again and add action group

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Note: The parameter override section maps the output from stack1 as an input parameter to stack2.

After the pipeline is created, all you have to do is upload cf.zip to the s3 bucket and watch the deployment.

No alt text provided for this image

I hope this article shows you the art of possible with AWS ClodePipleline and you would consider this as a tool to deploy cross regions.

Disclaimer:

  • This article is my personal opinion and has not been endorsed by AWS
  • This article addresses specific use-cases and may not be useful or applicable to everyone
  • Any AWS usage charges incurred by following this article is your responsibility

Steve Knockswell

Network Design Consultant at NSW e-Health

1 年

not sure if this is marketing for another AWS product (CodePipeline ) ? hard to keep track these days with all the software driven "innovational " product's launched one every 4 hours.... but it sure is useful. Love the diagrams and proper real-world use-cases. Commercialism aside.. i did learn something from this post. Thank you !

回复

要查看或添加评论,请登录

Vijay Shekhar R.的更多文章

社区洞察

其他会员也浏览了