Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to deploy in different environment (dev, uat ,prod) using cdk pipeline?

When I commit to develop branch it must deploy code to specific environment (dev). Similarly when i deploy to uat branch it must deploy to uat environment. How do i achieve this functionality in aws cdk pipeline ? There is stage and be deployed to multiple region but need to define if pushed to this branch then deploy to this environment likewise.

like image 257
Shrestha Bikesh Avatar asked Nov 04 '20 14:11

Shrestha Bikesh


1 Answers

The best approach depends on a few factors including whether your stack is environment agnostic or not (i.e. whether it needs to look up resources from within a given account.)

For simply switching between different accounts and regions, the CDK team has a decent writeup here which recommends a small wrapper script for each environment that injects the configuration by way of CDK_DEPLOY_ACCOUNT and CDK_DEPLOY_REGION environment variables.

If you want to provide other synth time context then you can do so via the context API, which allows you to provide configuration 'in six different ways':

Automatically from the current AWS account.

Through the --context option to the cdk command.

In the project's cdk.context.json file.

In the project's cdk.json file.

In the context key of your ~/.cdk.json file.

In your AWS CDK app using the construct.node.setContext method.

like image 168
Nick Cox Avatar answered Oct 18 '22 14:10

Nick Cox