Prepare the CDK

In this chapter we create the first CDK GO app. We use CDK V2 from the start.

Prepare

Node.JS has to be installed.

1 Install npx

NPX takes care of dealing with CDK and calling a version

npm install -g npx

2 find out cdk 2 version

See aws-cdk tags for the latest version.

Assume its version v2.0.0-rc.24

3 Alias CDK

On linux/mac you can create an alias to npx and the right CDK version. Version pinning, that is the process of using a fixed version of the CDK is vital when using the CDK.

alias cdk='npx cdk@v2.0.0-rc.24'

Test CDK version with:

cdk --version

If you do not get the current version, try the alternate approach “install CDK globally”:

Example for alias errors

 npx cdk@v2.0.0-rc.24 --version
npm ERR! cb.apply is not a function
...

3 Install CDK globally

npm i cdk@v2.0.0-rc.24 -g
unalias cdk

Test CDK version with:

cdk --version

After the preparation we can continue to the creation of an GO CDK APP in the next chapter.

4 Bootstrap Account

If you use CDK for the very first time or if the bootstrap version changes, you have to bootstrap your AWS account:

4.0 try automated bootstrap

cdk bootstrap

CDK tries to determine account and region automatically. If that’s work, fie you are done.

Otherwise continue:

4.1 Get Account number

aws sts get-caller-identity

Note the *“Account”: “555548271754”,

4.2 Call cdk bootstrap

Choose your aws region, here eu-central-1.

cdk bootstrap aws://555548271754/eu-central-1

Bootstrap creates an S3 bucket for deployment and some roles. You can inspect the CDKToolkit CloudFormation stack for details.

See also