Can I use a Cloud Formation template in stack set which will spin up different resources in different regions?

0

I have created a Cloud formation template in which i am spinning up two ec2 instances, server and client both of these are in the same region for now. But now, my requirement is to host the client in one region and server in other region. What all changes do I need to do in my existing Cloud Formation template to achieve this if it's possible. I tried finding a sample template that I can leverage but unable to find it. To sum up:- Can I create a single template which would go inside the stack set and will deploy my client in one region and server in other region?

Thanks,

asked 10 months ago713 views
3 Answers
1

Hi, yes, you can. You have a full sample here based on S3 buckets: https://www.cloudxs.ch/2021/02/deploy-into-multiple-aws-regions-with-cloudformation/

You will have to replace the bucket with an EC2 instance in your use case.

This lab may also help: https://www.wellarchitectedlabs.com/reliability/200_labs/200_deploy_and_update_cloudformation/6_multi_region_deploy/

Hope it helps! Didier

profile pictureAWS
EXPERT
answered 10 months ago
profile picture
EXPERT
reviewed 10 months ago
  • Hi, I think I was unable to elaborate my concern to you. Let's take an example of the template you shared above. So, How can I create 2 s3 bucket, one in us-east-1 and other in us-west-1 with totally different objects inside them using stack set from a single template?

0

Short answer: you can't. I recommend you use two different templates in two regions and update them independently.

As AWS CloudFormation is a regional service, there is no direct way within a template to create AWS resources in different regions than the one you are creating the stack in. There are although alternative workarounds that add complexity to your deployment:

  • You may want to use AWS StackSet and using conditions in order to deploy the same template in two regions and filter based on the region it is deployed in.
  • You may want to use a custom lambda function to create the resources in another region.

Note that updating resources in multiple regions that depend on each other is considered an anti-pattern and cannot properly be orchestrated within AWS.

Baw
answered 10 months ago
  • This is exactly what I did not want to hear, but anyways thanks for the suggestions.

0

You need to have a more elaborate solution to be able to achieve this combined with CF Stackset. What you are missing is an orchestration pipeline that can deploy stacks in various regions from a central place. these resources can give you an idea about the concept :

AWS
answered 10 months ago
  • Well, I need to list my template in AWS marketplace, so am not sure how would this CI/CD pipeline would come into picture there. Had it been used by just me, I would have done the CI/CD way but am quite skeptical with AWS Marketplace.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions