This example demonstrates how to use the AWS CDK to deploy a VPC with subnets, security groups and EC2 instances. We will be building the following.
You will need the following prerequisites installed in order to build and deploy the this project.
The AWS CDK uses Node.js (>= 10.3.0). To install Node.Js, follow the instructions in the Node.js website.
This project is developed in Typescript. Install Typescript using the following command.
npm install -g typescriptVerify that Typescript was installed correctly.
tsc --versionThe AWS CLI is a tool to manage your AWS services from a terminal session. Follow the steps to install the AWS CLI here.
Install the AWS CDK using the following command.
npm install -g aws-cdkVerify that the AWS CDK was installed correctly.
cdk --versionInstall npm modules
npm installCompile typescript to js
npm run buildDeploy this stack to your default AWS account/region
cdk deploynpm run buildcompile typescript to jsnpm run watchwatch for changes and compilenpm run testperform the jest unit testscdk deploydeploy this stack to your default AWS account/regioncdk diffcompare deployed stack with current statecdk synthemits the synthesized CloudFormation template
cdk destroy