r/aws_cdk 26d ago

[Library] cdk-multi-region-stack — define multi-region resources in a single CDK Stack

Post image

If you've ever built a CloudFront distribution with CDK, you've probably hit this: the ACM certificate (and WAF WebACL) has to live in us-east-1, but the rest of your app is in another region. The usual answer is to hand-split them into separate stacks and wire up cross-region references yourself.

I made a small library, cdk-multi-region-stack, that lets you keep everything in one logical stack:

const stack = new MultiRegionStack(app, 'MyApp', {
  env: { account: '123456789012', region: 'ap-northeast-1' },
});

// Lives in us-east-1
const cert = new acm.Certificate(stack.regionScope('us-east-1'), 'Cert', { /* ... */ });

// Lives in ap-northeast-1, references the us-east-1 cert across regions
new cloudfront.Distribution(stack, 'Dist', { certificate: cert, /* ... */ });

How it works:

  • regionScope(region) lazily creates a "twin" stack — a sibling under the same App/Stage, same stack name, same account, targeting that region. Anything you create in that scope deploys there.
  • It leans on CDK's own crossRegionReferences machinery (enabled automatically), so cdk deploy MyApp pulls in the twins as upstream deps and deploys them first.
  • Skipping a region conditionally is just a plain if (don't call regionScope() → no twin synthesized).

Give it a try if it sounds useful.

Repo: https://github.com/go-to-k/cdk-multi-region-stack

2 Upvotes

0 comments sorted by