AWS CDK(v2): Basic Settings

Page content

AWS CDK v2 is a tool that enables you to create and modify AWS infrastructure configurations by writing them in a programming language. At first, it was a snap to do from the web admin console, but as it becomes more and more difficult to do the same thing over and over again (quickly and without mistakes and without getting frustrated), this kind of standardized system is useful once you get used to it.

I think this CDK is very useful because it makes it easy to grant IAM privileges and to link various resources. I’m impressed by how easy it is to do things that would require me to go back and forth between various screens if I were to do them on the admin console. The basic things that can be done with CDK can also be done with CloudFormation, but if you choose TypeScript as the description language, CDK can complement property names and other information in a nice way if you edit them with VSCode, etc., and it can also detect combinations that cannot be used in advance. It is quite comfortable.

The AWS CDK was released to the public on December 2, 2021. It’s generally written in a similar way to v1, but there are some subtle differences, and existing samples often don’t work as they should, so I’m going to make a note of them.

Basic Settings

Reference: Getting Started in the official documentation.

Environments

  • MacBook Pro(M1), OS: Monterey(12.0.1)
  • node: v16.13.1

Setup AWS Account

There are many ways to do this, so I won’t go into that here (you can look it up). Basically, you need to configure credentials from aws configure or something like that.

Install NodeJS

We want the version16 of node to use aws-cdk, so we install it via nvm.

% brew install nvm
% nvm --version
0.39.0
% nvm install 16
% node --version
v16.13.1

Install AWS-CDK & TypeScript

Install aws-cdk and typescript.

% npm install -g aws-cdk typescript
% cdk --version
2.2.0 (build 4f5c27c)
% tsc --version
Version 4.5.4

Bootstrapping

You need to run bootstrap only once for each “AWS Account + Region”. For example, if your account number is 123456789 and your region is ap-northeast-1, you can do the following

cdk bootstrap aws://123456789/ap-northeast-1

If this is successful, the AWS account settings are also OK, and you can proceed to the next step.