Recently, Poppulo began the migration of our stack to AWS. In doing so it was decided that new products should be built out on AWS to ease the migration burden. It just so happened that my team had begun working on a new greenfield project and as such were required to build it on AWS. As a team we didn't have a lot of experience building on AWS and definitely didn't have experience using templating tools for creating and deploying our services.

Being a team of developers learning a new config based templating tool such as cloudformation or terraform didn't seem appealing, but after speaking with a colleague, he recommended that we should look at AWS CDK.

The AWS CDK is a library produced by AWS which allows cloudformation templates by coding in our favourite programming languages. For this post I will focus on Java as most tutorials focus on Typescript. For developers, writing application code and infrastructure code in the same programming language is a better experience.

After only a few minutes of using AWS CDK, the development pattern became repetitive and clear. Each resource is configured using a builder pattern and can be passed properties which in turn can be set using a builder pattern. This makes for fast learning curve and an enjoyable development experience. We quickly found ourselves repeating this pattern when building our own custom constructs and stacks.

Vpc templatesVPC = new Vpc(this, "TemplatesVPC", VpcProps.builder().subnetConfiguration(Collections.singletonList(SubnetConfiguration.builder().cidrMask(20).name(id+"PrivateSubnet").subnetType(SubnetType.ISOLATED).build())).build());

We started by trying to build out a simple REST api in lambda and accessed it via an API Gateway. This is really AWS 101 stuff. We were incredibly impressed at how simple it is to get up and running. In only a couple of lines of code we had a fully working endpoint.

//builds the lambda
Function helloWorldLambda = Function.Builder.create(this,"HelloWorldLambda")

//builds the api gateway
LambdaRestApi helloWorldAPIGateway = LambdaRestApi.Builder.create(this,"HelloWorldAPIGateway")

As we began to get deeper into AWS we constructed larger and more complex architectures. We built out VPC's, Fargate Clusters on EC2 and EKS Clusters and each came with its own implementation challenges using CDK. Most of these challenges arose due to our lack of understanding, but we noticed that using the typed programming languages intellisense feature helped guide us to what should be set when using different AWS services.

These tips alone were not enough to get us over the line. The best thing we learnt while working with the AWS CDK is to build out what you want first in the UI. This became apparent when attempting to access a private subnet in a VPC via a VPC Link from our API Gateway. We couldn't figure out what we needed to configure in CDK until we began playing with the UI and started understanding what the UI is configuring for you. After that we were able to map back the UI setup back to the CDK code and reproduce our setup repeatably.

In conclusion, for us CDK has been a great experience. As developers with no experience building out deployment files for AWS in a short space of time we were able to deploy rather complex setups.


  • Understand what you need to build out by using the UI first.
  • Using a good IDE allows the intellisense feature to help you.
  • Running CDK diff may catch things early.
  • Experiment with the configuration openings and always remember to clean up.