CDK Launch

Access your Cloud9 environment and launch the IaC (CDK) using the following steps:

Step1: Create a new CDK project using below command. Default language is Typescript:

cd cdk
cdk init

Step2: Install the required modules defined in package.json file for this CDK stack using below command. It will create node_modules directory:

npm install

It should end with message "found 0 vulnerabilities".

Step3: Compile the packages to js and then check the cdk empty stack listing:

npm run build
cdk ls

The command "npm run build" should end with no error messages and the command "cdk ls" should output a cdk stack name "CdkStackEksALBBg".

Step4: Generate CloudFormation template from the CDK:

cdk synth

Step5: Bootstrap the CDKToolkit CloudFormation stack into your environment(s), where an S3 bucket will be created to store synthesized templates and the related assets, before triggering a CloudFormation stack update in the next step:

cdk bootstrap aws://$ACCOUNT_ID/$AWS_REGION

If the CDK toolkit staging S3 bucket does not exist, this command will create one with following messages:

 0/2 | 6:55:15 PM | CREATE_IN_PROGRESS   | AWS::S3::Bucket | StagingBucket 
 0/2 | 6:55:16 PM | CREATE_IN_PROGRESS   | AWS::S3::Bucket | StagingBucket Resource creation Initiated
 1/2 | 6:55:37 PM | CREATE_COMPLETE      | AWS::S3::Bucket | StagingBucket 
 2/2 | 6:55:38 PM | CREATE_COMPLETE      | AWS::CloudFormation::Stack | CDKToolkit

S3 bucket named "cdktoolkit-stagingbucket-" is created for that region.

Step6: Deploy the CDKToolkit to trigger the CloudFormation stack to execute:

cdk deploy

You may be asked to confirm the creation of the roles and authorization before the CloudFormation is executed, for which, you can respond with a "Y".

The infrastructure will take some time to be created, please wait until you see the Output of CloudFormation printed on the terminal. Until then, take time to review the CDK code in the below file: cdk/lib/cdk-stack.ts

You may also check and compare the CloudFormation Template created from this CDK stack: