Question #978
A developer is deploying a serverless application to multiple AWS accounts using the AWS CDK. The application includes AWS Lambda functions that use Docker images stored in Amazon ECR. The developer successfully deployed the application to the development account in us-east-1 using cdk deploy. They are now attempting the first deployment to the staging account in us-west-2 without modifying the CDK code. The deployment fails with an error stating that the specified ECR repository does not exist.
Which command should the developer execute prior to redeployment to fix this issue?
cdk synth
cdk bootstrap
cdk init
cdk destroy
Explanation
Answer B is correct because:
1. cdk bootstrap sets up foundational resources (e.g., S3 buckets, ECR repositories) in a target AWS account/region for CDK deployments.
2. The error occurs because the staging account in us-west-2 lacks the ECR repository created during bootstrapping.
3. Other options:
- A. cdk synth only generates CloudFormation templates and does not create infrastructure.
- C. cdk init initializes a new CDK project, irrelevant here.
- D. cdk destroy removes deployed resources, which would worsen the issue.
Key takeaway: Always run cdk bootstrap for new accounts/regions to provision CDK prerequisites.
Answer
The correct answer is: B