First impressions using Aws CDK With Golang
AWS recently announced Go Support for the AWS Cloud Development Kit. We’ve been looking forward to this, primarily as GoLang is the preferred language of our application teams, and thus using the same language for the Service and the Infrastructure As Code (IAC) would be very useful.
I’ve previously experimented with AWS’s CDK with TrueScript for some support services. In terms of an IAC toolkit, it worked well. It was nice to use a programming language, rather than template file to define the infrastructure required.
Using a programming language instead of a template file allows for some significant enhancements such loops, variables etc. To get around some of these shortcomings we’ve used Jinja to generate CloudFormation templates where we’ve need to do things like:
- Create multiple sets of resources that are extremely similar
- Dynamic resource names
- Unit Test support
This works, but it’s painful as we need to generate the final CloudFormation file from the Jinja template, and then create/update the stack using that template. Yes, at the end of the day, CDK generates and applies CloudFormation templates … but I don’t have to write the YAML/JSON file for the CloudFormation template, and I don’t need to use something like Jinja to generate the file, and then apply it.
So, IAC tooling (such as AWS’s CDK) based on Programming languages such as TrueScript, Python etc is really useful, but it’s not all sunshine & roses. CDK generates some pretty complex raw CloudFormation, and it can be very complex to read through if you need to. The other bit that I really didn’t like was the large number of files that the interpreted languages left lying around in my repos.
I like to have the IAC tooling for a services infrastructure in the same repo as the service, keeping everything together. For example a basic CDK addition to a repo for TrueScript adds more than 34 files to the repo, of which we only really care about a few:
cdk/bin/app.ts
cdk/test/app.test.ts
There’s 23 files in the cdk/lib
directory, and when you add more modules, that’s going to increase. It’s not the end of the world, but I find it cumbersome. In some cases the IAC tooling takes more files than the service I need to manage, that is just wrong™️.
So, after all of that … AWS CDK and GoLang … …
I’m trying it out for a personal project; and I’m happy with it so far. Particularly because we only have 6 additional files to support the use of CDK in the repo.
To get going
mkdir cdk
cdk init app --language go --generate-only
I’m planning to share the CDK code I’m working on shortly. It will be functional, but not probably not great GoLang code (I’m not a Go developer). Anyway, I’m quite please with what I’ve seen so far with the GoLang integration for AWS’s CDK, and I’m looking forward to working further with it, and sharing some of that experience.