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.
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
领英推荐
Edit the deploy stage again and add action group
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.
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:
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 !