
Table of content
Core Principles for Multi-Region CDK Deployment
-
Separate Global and Regional Resources:
-
Global Services: CloudFront, IAM roles (though their policies might reference regional resources), Route 53 (for public hosted zones), and Public Keys/KeyGroups for CloudFront are global. These generally need to be defined and deployed once, often in a designated “primary” or “global” region (historically
us-east-1for CloudFront certificates). -
Regional Services: Lambda functions, S3 buckets, Secrets Manager secrets, DynamoDB tables (unless Global Tables are used), and regional API Gateways are regional. These will be deployed to each target region.
-
-
Parameterization and Configuration:
-
Use configuration files (e.g.,
cdk.json, environment variables, or custom config files) to define the regions you want to deploy to. -
Pass region-specific values as props to your CDK stacks. This allows you to have a single codebase that can be deployed with different settings per region.
-
-
Cross-Stack/Cross-Region References:
-
Within the same app/account: CDK allows passing construct references between stacks within the same CDK application.
-
Cross-Region (and cross-account): For resources deployed in one region that need to be referenced by resources in another (e.g., a CloudFront distribution in
us-east-1needing to know the ARN of an S3 bucket ineu-west-1), you’ll need to use mechanisms like:-
SSM Parameter Store: Store ARNs or other identifiers of global/primary-region resources in SSM Parameter Store in the primary region. Regional stacks can then read these parameters.
-
CfnOutput/fromLookup: Use
CfnOutputin the stack that creates the resource andfromLookuporfromArnin the consuming stack to import the resource. This is more common for cross-stack within the same region, but can be adapted for cross-region with a bit more orchestration (e.g., manually retrieving the output from one CloudFormation stack and passing it as input to another). -
Custom Resources: For more complex cross-region data exchange or actions, you might consider custom resources backed by Lambda functions.
-
-
-
Naming Conventions:
-
Include the region in the stack ID to ensure uniqueness when deploying the same stack across multiple regions (e.g.,
MyServiceStack-us-east-1,MyServiceStack-eu-west-1). This is a critical best practice to avoid deployment conflicts. -
For regional resources, consider including the region in their names (e.g.,
my-s3-bucket-us-east-1).
-
-
Deployment Orchestration (CI/CD):
-
AWS CodePipeline/CodeBuild: Set up a pipeline that can sequentially or in parallel deploy your regional stacks.
-
Phased Deployments: Deploy global resources first (e.g., CloudFront, global IAM roles), then regional resources. Ensure dependencies are respected.
-
Rollback Strategy: Plan for how you’ll roll back changes across multiple regions if a deployment fails in one.
-
Specific Considerations for Your Services
-
IAM:
-
IAM roles and policies are global. Define them once.
-
If a Lambda function in
us-east-1needs to access an S3 bucket ineu-west-1, ensure the IAM policy attached to the Lambda’s execution role grants permissions to the specific S3 bucket ARN ineu-west-1. You can construct these ARNs dynamically based on the region. -
Be mindful of IAM role exhaustion if you’re creating many similar roles across regions without careful planning. Consider creating generic roles where appropriate and attaching granular policies.
-
-
CloudFront (KeyGroup, Public Key):
-
CloudFront distributions, KeyGroups, and Public Keys are global resources.
-
The ACM Certificate associated with CloudFront must be in
us-east-1. You’ll need a separate CDK stack specifically for deploying this certificate tous-east-1. -
Your main application stack (which might be deployed to other regions) will then need to reference this certificate. This is a classic example of cross-region reference using
CfnOutputandfromLookupor passing the ARN as a prop. -
You’ll typically create one CloudFront distribution that can serve content from origins in multiple regions (e.g., S3 buckets in different regions, or regional API Gateway endpoints). Use Origin Groups with failover or Lambda@Edge to route requests to the closest or healthiest regional origin.
-
-
Secrets Manager:
-
Secrets Manager secrets are regional. If a Lambda in
eu-west-1needs a secret, it must be deployed ineu-west-1. -
If you need the same secret value across multiple regions, you’ll need to create the secret in each region.
-
Consider a secure way to replicate or manage these secrets, or if they are truly identical, use a centralized mechanism (like a “seed” secret in one region and a custom resource to replicate it, though this adds complexity).
-
-
Lambda:
-
Lambda functions are regional. Each region will have its own instance of your Lambda.
-
If your Lambdas need to interact with regional services, ensure they are configured to target the correct region (e.g., an S3 bucket in the same region).
-
Consider using Lambda@Edge for functions that need to run globally at CloudFront edge locations (e.g., for request/response manipulation). These are deployed from
us-east-1but execute globally.
-
-
S3:
-
S3 buckets are regional. You’ll likely have a separate S3 bucket for each region.
-
S3 Replication: If you need the same data available in multiple regions for high availability or disaster recovery, configure S3 Cross-Region Replication between your regional buckets.
-
CloudFront can point to S3 buckets as origins
-