You can find the 5-minute video that walks through all of the steps described here.
In this episode, we'll be looking at AWS Cloud Development Kit (CDK). With the CDK, you can define your cloud infrastructure using familiar programming languages such as TypeScript, Python, and Java. The CDK synthesizes your high-level programming language code into CloudFormation templates that it manages in your AWS account.
As part of the AWS Construct Library, you can use Level 1, Level 2, and Level 3 constructs to build your CDK applications - as described below.
- Level 1 - Map directly to CloudFormation resources. This is the core CDK framework.
- Level 2 - Are curated by the AWS CDK team. These also represent AWS resources but provide property defaults and convenience methods that make it simpler to work with the resource.
- Level 3 - These are patterns that use multiple CloudFormation resources.
Provision an S3 bucket using a CDK Level 1 Construct in TypeScript as shown below.
const bucket = new s3.CfnBucket(this, "MyBucket", {
bucketName: "MyBucket"
});
Here is the same resource as defined in an AWS CloudFormation template.
Resources:
S3Bucket:
Type: 'AWS::S3::Bucket'
DeletionPolicy: Retain
Properties:
BucketName: MyBucket
From your AWS CloudShell Environment in the us-east-2 region, run the following commands:
sudo rm -rf ~/aws-cdk-examples
git clone https://github.com/aws-samples/aws-cdk-examples.git
cd aws-cdk-examples/typescript/lambda-cron
sudo npm install -g aws-cdk
npm install
npm run build
cdk synth > cdk-cfn.yml
cdk deploy
- You will receive this message: Do you wish to deploy these changes (y/n)? - Type
y
. - AWS Lambda Applications
- Select the Lambda Function in the Lambda application
- Select the EventBridge Rule in the Lambda application
- See the CloudFormation Stack generated by the CDK. You can also view the file by opening the
cdk-cfn.yml
file you synthesized from the CLI. - View the
index.ts
in the current directory to see how CDK apps are written.
There is no additional cost for using the AWS CDK. You are only charged for the use of the resources that the CDK provisions.
cdk destroy
You will receive this message: Are you sure you want to delete: LambdaCronExample (y/n)? - Type y
.