ENES

AWS CDK

Describe your AWS infrastructure in a real programming language instead of YAML.

A few lines of TypeScript become, after cdk synth, a long CloudFormation template, which cdk deploy turns into a bucket, a function and a queue

AWS CDK (Cloud Development Kit) is an infrastructure as code tool where you describe servers, buckets, queues and permissions in TypeScript, Python, Java, C# or Go. Under the hood it does not talk to AWS directly: it synthesizes your program into an AWS CloudFormation template, and CloudFormation creates or updates the resources. The two key commands are cdk synth, which produces the template, and cdk deploy, which applies it.

Writing a real program brings the things programmers are used to: loops, functions, autocompletion, type checks, tests, and packages to share code. A few lines like new s3.Bucket(this, 'Uploads', { versioned: true }) can expand into dozens of lines of template. Ten similar environments become one loop instead of ten copied files.

The building blocks are constructs, which come in levels. Low-level ones map one-to-one to CloudFormation resources. Higher-level ones bundle sensible defaults (a bucket that is encrypted and blocks public access unless you say otherwise), and the highest-level ones assemble whole patterns, like a load-balanced container service. One helper worth knowing: bucket.grantRead(fn) writes the IAM policy for you, scoped to exactly that bucket. Each account and Region needs a one-time cdk bootstrap before the first deploy.

Keep in mind

Go deeper

Related terms

More in AWS