Is it possible to deploy a stack to multiple regio...
# help
p
Is it possible to deploy a stack to multiple region. Something as follows.
Copy code
new StackA()
new StackB()
for (const region of ['us-east-1', 'us-east-2']) {
  new StackC(region)
}
ö
I believe so
Should be easy to test
Isnt it working
f
Yeah, that should work. Usually I’d recommend deploying entire app to multiple regions:
Copy code
sst deploy --region us-east-1
sst deploy --region us-east-2
@Pavan Kumar in your case, it seems you don’t want to deploy
StackA
and
StackB
to multiple regions. Can you elaborate on ur use case?
ö
Yeah this seems better
p
@Frank Use case: I am building the IoT app. I want only IoT related infrastructure to deployed to few region. Those IoT endpoints process the data and send it to central location, in my example StackA and StackB.
f
Got it. See if this setup makes sense to you:
Copy code
if (app.region === "us-east-1") {
  new StackA()
  new StackB()
}
new StackC()
And you can deploy to:
Copy code
sst deploy --region us-east-1
sst deploy --region us-east-2
I’d like to think of an app as something that I can take it and deploy to any AWS account any region.
Or even better, I’d do this:
Copy code
if (app.stage === "prod") {
  new StackA()
  new StackB()
}
new StackC()
And you can deploy to:
Copy code
sst deploy --stage prod --region us-east-1
sst deploy --stage prod-us-east-2 --region us-east-2
sst deploy --stage prod-us-west-1 --region us-west-1
sst deploy --stage prod-us-west-2 --region us-west-2
This way, you have your 1 main
prod
stage, and X
prod-$region
stages. From the name of the stage, you know
prod
has all resources, and
prod-$region
only has region specific resources.
p
Hmm... Isn't it nice to think whole app as single deployment which includes stack for other regions. One advantage of this way is I can send resources details of StackA and StackB to multi region StackC. For example StackC needs to know about SQS created by StackA.
f
hmm.. that makes sense. Let me get @thdxr and @Jay to take a look at this.
t
I think this is challenging because CloudFormation is region specific right?
So a "deployment" from AWS's perspective is specific to a region (minus the cross region hacks for us-east-1 locked stuff). Is it even possible for a cross stack output between regions? I need to investigate CDK patterns for multi-region.
f
@thdxr is right. In CDK, you are not allowed to reference StackA resources in StackB if StackB is in a different region. You will get an error.
t
I think I personally would either have 2 separate SST apps - one for multi region stuff and another for my normal region specific stuff. Second choice would be frank's first example where I conditionally initialize stacks based on the region I'm deploying to and I'd run the deploy command once per region
The reason AWS doesn't make this easy is they're very opinionated about cell based infrastructure. This means they heavily encourage regions being as independent as possible, so they do not encourage cross region dependencies. It's the pattern they follow internally which is why you usually see region specific outages (like the us-east-2 one from last week) whereas with other clouds like Google Cloud you see global outages
p
t
I was wondering if region was a stack prop you can pass. Still not sure if cross stack references will work between regions
Oh but if you look they only synth + deploy one region at a time
p
Oh!
If I do deployment as follows.
Copy code
sst deploy --region us-east-1
sst deploy --region us-east-2
Is it possible to use exported named output of one region to another region, as follows.
Copy code
new CfnOutput(this, "TableName", {
  value: bucket.bucketArn,
  exportName: "MyBucketArn",
});
f
I don’t think you can do that with CloudFormation exports.
Maybe you can call CloudFormation’s SDK API manually to get the stack outputs from another region.