To Nha Notes | Feb. 23, 2022, 11:01 a.m.
Welcome to the AWS Cloud Development Kit (CDK) Developer Guide. This document provides information about the AWS CDK, a framework for defining cloud infrastructure in code and provisioning it through AWS CloudFormation.
The AWS CDK supports TypeScript, JavaScript, Python, Java, C#/.Net, and (in developer preview) Go. Developers can use one of these supported programming languages to define reusable cloud components known as Constructs. You compose these together into Stacks and Apps.

TypeScript 2.7 or later
npm -g install typescript
Install the AWS CDK Toolkit globally
npm install -g aws-cdk
Install dependencies
npm install
The actual package name of the main CDK package varies by language (not required?).
npm install aws-cdk-lib
You can specify the names of multiple stacks to be synthesized or deployed in a single command. If your app defines only one stack, you do not need to specify it.
cdk ls # list stacks
cdk synth # app defines single stack
cdk synth "Stack?" # Stack1, StackA, etc.
cdk deploy Happy Grumpy # app defines two or more stacks; two are deployed
cdk deploy "*Stack" # PipeStack, LambdaStack, etc.
Tip: you don't need to explicitly synthesize stacks before deploying them; cdk deploy performs this step for you to make sure your latest code gets deployed.
Following these guidelines will help make your code consistent with other AWS CDK applications as well as easier to understand.
Use ES6-style import directives, not require().
Generally, import individual classes from aws-cdk-lib.
import { App, Stack } from 'aws-cdk-lib';If you need many classes from aws-cdk-lib, you may use a namespace alias of cdk instead of importing the individual classes. Avoid doing both.
import * as cdk from 'aws-cdk-lib';Generally, import AWS service constructs using short namespace aliases.
import { aws_s3 as s3 } from 'aws-cdk-lib';Adding a topic property allows consumers to access the inner topic, as shown in the following example:
export class NotifyingBucket extends Construct {
public readonly topic: sns.Topic;
constructor(scope: Construct, id: string, props: NotifyingBucketProps) {
super(scope, id);
const bucket = new s3.Bucket(this, 'bucket');
this.topic = new sns.Topic(this, 'topic');
bucket.addObjectCreatedNotification(new s3notify.SnsDestination(this.topic), { prefix: props.prefix });
}
}
Now, consumers can subscribe to the topic, for example:
const queue = new sqs.Queue(this, 'NewImagesQueue');
const images = new NotifyingBucket(this, '/images');
images.topic.addSubscription(new sns_sub.SqsSubscription(queue));
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam-readme.html
https://bobbyhadz.com/blog/managed-policy-aws-cdk
https://github.com/bobbyhadz/managed-policy-aws-cdk/blob/master/lib/cdk-starter-stack.ts
https://bobbyhadz.com/blog/aws-cdk-iam-role
https://github.com/bobbyhadz/aws-cdk-iam-role/blob/master/lib/cdk-starter-stack.ts
https://docs.aws.amazon.com/cdk/v2/guide/context.html
https://yshen4.github.io/infrastructure/AWS/CDK_context.html
https://docs.aws.amazon.com/cdk/v2/guide/home.html
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-construct-library.html
https://github.com/kevinslin/open-cdk
https://github.com/kolomied/awesome-cdk
https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript
https://bobbyhadz.com/blog/aws-cdk-tutorial-typescript
https://bobbyhadz.com/blog/aws-cdk-s3-lifecycle-rules
AWS Toolkit for Visual Studio Code