Hey friend,
I have a aws pipeline that will deploy stuffs to the regions other than where it locates, which requires the creation of cross-region s3 buckets. Below is the code snippet:
export interface PipelineProps extends CDK.StackProps {
deploy: {stage: 'dev' | 'qa' | 'uat' | 'prod', regions:string[]},
github: { owner: string, repository: string, tokenName: string }
}
let myCrossRegionReplicationBuckets: { [region: string]: S3.IBucket; } = {}
for (const reg of props.deploy.regions) {
myCrossRegionReplicationBuckets.reg = new S3.Bucket(this, `${reg}-pipeline-bucket`, {
versioned: true,
encryption: S3.BucketEncryption.S3_MANAGED
})
}
const pipeline = new CodePipeline.Pipeline(this, id, {
crossRegionReplicationBuckets: myCrossRegionReplicationBuckets,
restartExecutionOnUpdate: true,
})
I noticed CDK.StackProps has a filed of env that includes one accountId and one region.
My question is: Is there a way to create the buckets in the regions defined in props.deploy.regions instead of that defined in props.env.region?
thanks.
short answer: you can't.
long answer: when you deploy a stack it is deployed to CloudFormation in a specific region, that region is where resources are created.
Generally, updating more than one region at a time is considered an anti-pattern we encourage our users to avoid.
@richardhboyd would you mind expanding on that?
I may be completely off base here since I'm not using CDK yet, but I get the impression that CDK is an abstraction layer on top of CloudFormation to make it easier and OOP-driven. Why would CDK be against building a cross-region deployment pipeline since CloudFormation itself supports creating an AWS CodePipeline that does exactly that?
AWS CodePipeline supports cross-region deployment by deploying a specific stack in a specific region. If you wanted to deploy the same stack to multiple regions in CodePipeline, you would have to create 1 deployment action per region you wanted to deploy to.
AWS CloudFormation StackSets deploy a copy of each stack to each region, therefore each region has its own stack.
AWS Organization StackSets operate on the same principle as CloudFormation StackSets, just with some additional automation built in at the account creation process.
It is not possible to update resources across multiple regions with a single stack. I think its important to note the difference between "updating RegionA from RegionB" (well supported) and "updating RegionA and RegionC as an atomic transaction fromRegionB" (actively discouraged).
It is completely possible to build a cross-region deployment pipeline with CDK, what is not supported is updating multiple regions in a single stack because that capability is not present in CloudFormation.
@richardhboyd thanks for that, I know understand and agree with what is discouraged!!
Closing this issue since it seems to have been resolved. Feel free to reopen if that's not the case.
Most helpful comment
AWS CodePipeline supports cross-region deployment by deploying a specific stack in a specific region. If you wanted to deploy the same stack to multiple regions in CodePipeline, you would have to create 1 deployment action per region you wanted to deploy to.
AWS CloudFormation StackSets deploy a copy of each stack to each region, therefore each region has its own stack.
AWS Organization StackSets operate on the same principle as CloudFormation StackSets, just with some additional automation built in at the account creation process.
It is not possible to update resources across multiple regions with a single stack. I think its important to note the difference between "updating RegionA from RegionB" (well supported) and "updating RegionA and RegionC as an atomic transaction fromRegionB" (actively discouraged).
It is completely possible to build a cross-region deployment pipeline with CDK, what is not supported is updating multiple regions in a single stack because that capability is not present in CloudFormation.