The CDK Book: The missing Go Code Examples

The CDK Book

The CDK Book “A Comprehensive Guide to the AWS Cloud Development Kit” is a book by Sathyajith Bhat, Matthew Bonig, Matt Coulter, Thorsten Hoeger written end of 2021.

Because the CDK itself is polyglott with jsii, the TypeScript examples are automatically translated in other languages. So the example CDK code used in the book is jsii generated, and there are samples for TypeScript, Python, Java and C#.

If you buy the book from gumroad, you get different versions for Typescript, Python, Java and C#. The content itself is mostly focused on TypeScript, which makes sense, since the CDK is mainly written in TypeScript. A few chapters for Python are also included. The testing part is typescript-only.

What is missing is example content for GO. No problem, we got this covered! We have running examples for almost every chapter.This is a part of my project “Go on AWS”.

Go Samples For the CDK Book

Whenver it is possibly I provide synth-able code snippets, that means cdk synth produces an output. The examples usually do not generate useful code, they are just learning examples.

If the snippets are to small, I provide a readme.

* TCB = The CDK Book * GoA = Go on AWS Webseite

TCB* Chapter 2: What Are Constructs?

TCB Chapter 2.2.3. Level 2 Constructs

TCB Chapter 2.3.1. The Stack Construct

TCP Chapter 4.2.2 Tasks

As an alternative: see Chapter Tools-Task

TCP Chapter 4.2.3 Debugging

Debugging should work out of the box with vscode:


Just start (1) Debugging.

Standard Launch Json:

    "version": "0.2.0",
    "configurations": [
            "name": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}"

TCP Chapter 4.2.4 Linting

.. is included in GO.

For formatting run : go fmt *.go

TCP Chapter 5 Project Layout

Notes on files:

  • tsconfig.json - not needed with GO

  • package.json - the go.mod has almost the same functionality, see Chapter Modules

  • .gitignore - the same functionality

  • .npmignore - not needed



  • bin/* => main/main.go
  • lib/* => files wil be in the project root and subdirs


As GO does not need so much helper files and handles dependencies better since 1.13, projen is not needed. Please note: projen is not CDK standard project layout.

TCP Chapter 5.1.11. Initializing with the CLI

npx cdk init app --language=go


npx cdk init app -l=go

TCP Chapter 6 Custom Resources and CFN Providers

TCP Chapter 6.1.1. Implementing custom resources using AWS CDK

TCP Chapter 6.2. CloudFormation Resource Types

TCP Chapter 7. Configuration Management


TCP Chapter 7.1. Configuration Management


TCP Chapter 7.1. Static Files

The kind of configuration is different for the several languages.

Here an example for using Systems Manager with paddle “” and configuration files with “viper” “”

The example is a working webserver instance example. Note the in the source directory

TCP Chapter 7.3.1. Systems Manager Parameter Store

awsssm.NewStringParameter(stack, aws.String("Parameter"),
		AllowedPattern: aws.String(".*") ,
        Description:   aws.String("The value Foo"),
        ParameterName: aws.String("FooParameter"),
        StringValue:   aws.String("Foo"),
		Tier: awsssm.ParameterTier_ADVANCED,

TCP Chapter 8.3.1 Docker Image Asset in Action: ECS Fargate

A similar example is in the architecture section

TCP 8.4.1. S3 Assets in Action: Deploying Lambda Functions using S3 Assets

A similar example is in the Lambda Construct section:

TCP 8.5 Docker Bundling

TCP 9 Testing

Most of the concepts are described with code examples in

See the full source on github.

Feedback & discussion

For discussion please contact me on twitter @megaproaktiv

Learn more GO

Want to know more about using GOLANG on AWS? - Learn GO on AWS: here

Similar Posts You Might Enjoy

Views of the Pyramids: From a monolithic Test process to a Serverless Test Automation with CodeBuild

Comparing the development methodology of a monolithic program to a Serverless IAC application you will see that the power of DevOps lies in automating everything. I will show you a working example of a serverless CI pipeline with automated unit, integration and end2end test and test reports in CodeBuild. The full source is written GO, with references to Node.JS and python for the test parts. - by Gernot Glawe

Cloud Driven Development Workshop@devopenspace

This is a live Blog from the workshop “Cloud Driven Development” on Forget a lot of what you know about classic full-stack development. Together, we’ll dive into cloud-driven software development and build a sample serverless application in AWS. This blog was build live during the workshop on November 2021. So it`s not a complete reference, just a few hints to test and deploy the infrastructure and the applications. - by Gernot Glawe

Lambda Container Deployment with CDK: Using Arm based Lambda with GO

End of September 2021, AWS announced Graviton 2 powered Lambda Functions. The announcement post says “All Lambda runtimes built on top of Amazon Linux 2, including the custom runtime, are supported on Arm…”. Not all languages out of the box, for using GO as fast language on a fast Graviton processor, you have to use Docker based deployment. Here I show you a simple - CDK powered way to do that. - by Gernot Glawe