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 typescript
Verify that Typescript was installed correctly.
tsc --version
The 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-cdk
Verify that the AWS CDK was installed correctly.
cdk --version
Install npm modules
npm install
Compile typescript to js
npm run build
Deploy this stack to your default AWS account/region
cdk deploy
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template
cdk destroy