This is a blank project for CDK development with TypeScript.
The cdk.json
file tells the CDK Toolkit how to execute your app.
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
AWS Client AWS CDK Node.js Typescript
AWS Cli installation
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Configure AWS Client
aws configure
AWS CDK installation
npm i -g aws-cdk
Typescript installation
npm i -g typescript
Check versions
aws --version
node --version
cdk --version
npm --version
https://docs.aws.amazon.com/cdk/v2/guide/best-practices.html
With the AWS CDK, developers or administrators can define their cloud infrastructure by using a supported programming language. CDK applications should be organized into logical units, such as API, database, and monitoring resources, and optionally have a pipeline for automated deployments. The logical units should be implemented as constructs including the following:
- Infrastructure (such as Amazon S3 buckets, Amazon RDS databases, or an Amazon VPC network)
- Runtime code (such as AWS Lambda functions)
- Configuration code
https://docs.aws.amazon.com/cdk/v2/guide/cli.html
The AWS CDK Toolkit, the CLI command cdk, is the primary tool for interacting with your AWS CDK app. It executes your app, interrogates the application model you defined, and produces and deploys the AWS CloudFormation templates generated by the AWS CDK. It also provides other features useful for creating and working with AWS CDK projects. This topic contains information about common use cases of the CDK Toolkit.
Command | Function |
---|---|
cdk list (ls) | Lists the stacks in the app |
cdk synthesize (synth) | Synthesizes and prints the CloudFormation template for one or more specified stacks |
cdk bootstrap | Deploys the CDK Toolkit staging stack; see Bootstrapping |
cdk deploy | Deploys one or more specified stacks |
cdk destroy | Destroys one or more specified stacks |
cdk diff | Compares the specified stack and its dependencies with the deployed stacks or a local CloudFormation template |
cdk metadata | Displays metadata about the specified stack |
cdk init | Creates a new CDK project in the current directory from a specified template |
cdk context | Manages cached context values |
cdk docs (doc) | Opens the CDK API Reference in your browser |
cdk doctor | Checks your CDK project for potential problems |
https://aws.amazon.com/pt/visualstudiocode/
The AWS Toolkit for Visual Studio Code is an open source plug-in for the Visual Studio Code that makes it easier to create, debug, and deploy applications on Amazon Web Services. With the AWS Toolkit for Visual Studio Code, you will be able to get started faster and be more productive when building applications with Visual Studio Code on AWS. The toolkit provides an integrated experience for developing serverless applications, including assistance for getting started, ML-powered code recommendations, step-through debugging, and deploying from the IDE.
https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html
Bootstrapping is the process of provisioning resources for the AWS CDK before you can deploy AWS CDK apps into an AWS environment. (An AWS environment is a combination of an AWS account and Region).
Deploying stacks with the CDK requires special dedicated AWS CDK resources to be provisioned. The cdk bootstrap command creates the necessary resources for you. You only need to bootstrap if you are deploying a stack that requires these dedicated resources.
cdk bootstrap
If issued with no arguments, as shown here, the cdk bootstrap command synthesizes the current app and bootstraps the environments its stacks will be deployed to. If the app contains environment-agnostic stacks, which don't explicitly specify an environment, the default account and Region are bootstrapped, or the environment specified using --profile.
The cdk deploy subcommand deploys one or more specified stacks to your AWS account.
cdk deploy # if app contains only one stack
cdk deploy MyStack
cdk deploy Stack1 Stack2
cdk deploy "*" # all stacks in app
"Turn of the lights before leaving the room" Werner Vogels Amazon CTO
The AWS CDK attempts to keep you from losing data by defaulting to policies that retain everything you create. For example, the default removal policy on resources that contain data (such as Amazon S3 buckets and database tables) is not to delete the resource when it is removed from the stack. Instead, the resource is orphaned from the stack. Similarly, the CDK's default is to retain all logs forever. In production environments, these defaults can quickly result in the storage of large amounts of data that you don't actually need, and a corresponding AWS bill.
Consider carefully what you want these policies to be for each production resource and specify them accordingly. Use Aspects to validate the removal and logging policies in your stack.
cdk destroy
show available templates with:
cdk init --list
init a template (be carefull because it will create a new project simmilar to this one):
cdk init sample-app --language=typescript