Skip to content
Chris Chen

Using CDK with Go - a recent brown bag talk and some thoughts

AWS, CDK, Speech, Go1 min read

I just presented a CDK intro session to the engineering folks at David Jones and Country Road group. Since I worked with this client last year, I've got some insights into their current Infra-as-Code, CI/CD, and programming practices.

thumbnail

demo project code on github.com/chrischenyc/cdk-in-go-brown-bag


Since CloudFormation, Go, and Python are predominately used at this organisation, I thought I might demonstrate CDK with Go, instead of with TypeScript, to remove the programming language barrier for my audience. It also gave me a chance to gain some first-hand experience in writing CDK code with a programming language other than TypeScript, which is the first citizen in the CDK community.

I've been using CDK (v1 and v2) with TypeScript for nearly a year, switching to using CDK with Go makes me feel clumsy. Besides my rusty Go skill, I find having to use the jsii functions to convert primitive data types makes the experience less enjoyable. Take the code below, for example, to define a pretty standard S3 bucket configuration, how many times have I just typed a string or a boolean, then got reminded by the code editor that I should've used jsii.String() or jsii.Bool() instead, and I cursed and grunted.

1import (
2 "github.com/aws/aws-cdk-go/awscdk/v2"
3 "github.com/aws/aws-cdk-go/awscdk/v2/awss3"
4 "github.com/aws/jsii-runtime-go"
5)
6
7// too many jsii ... 🤦‍♂️
8bucket := awss3.NewBucket(stack, jsii.String("bucket"), &awss3.BucketProps{
9 BucketName: jsii.String("bucket-name"),
10 Versioned: jsii.Bool(true),
11 Encryption: awss3.BucketEncryption_S3_MANAGED,
12 BlockPublicAccess: awss3.BlockPublicAccess_BLOCK_ALL(),
13 EnforceSSL: jsii.Bool(true),
14 // ...
15})

Other than this, I find writing CDK code in Go is close to writing it in TypeScript: the VS Code IntelliSense works fairly well with CDK Go packages, the CLI experience is identical. Given a week of intensive use, I should be able to build new muscle memory and gain better velocity.


To address one of the questions asked during the session:

How much time does it take for someone to get up to speed with CDK?

I listed 4 prerequisites:

  1. a good understanding of the AWS services you are about to use
  2. a basic understanding of AWS CloudFormation and how to troubleshoot its deployments
  3. a good understanding of the programming language (and tooling) you choose to write the CDK code
  4. a week or two of intensive practice

So yeah, the short answer is again, "it depends".


To help the decision-making (should I switch to CDK?), I listed a few pros and cons.

why or why not

You can find the slides and demo project I used on github.com/chrischenyc/cdk-in-go-brown-bag