The CDK Book is a book by Sathyajith Bhat, Matthew Bonig, Matt Coulter, Thorsten Hoeger written end of 2021.
The code for the book is jsii generated, and there are samples for TypeScript, Python, Java and C#.
At the time beeing there are no GO samples in the book. So here I create some of the Samples for you.
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
*
Chapter 2: What Are Constructs?As an alternative: see Chapter Tools-Task
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}"
}
]
}
.. is included in GO.
For formatting run : go fmt *.go
For serverless project layout: Chapter Lambda with CDK Overview
For general project layout: Chapter Exercise CDK-VPC
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
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.
npx cdk init app --language=go
Shortform
npx cdk init app -l=go
simpleapiwithtestsstack:
DBStack:
The kind of configuration is different for the several languages.
Here an example for using Systems Manager with paddle “github.com/PaddleHQ/go-aws-ssm” and configuration files with “viper” “github.com/spf13/viper”
The example is a working webserver instance example. Note the readme.md in the source directory
awsssm.NewStringParameter(stack, aws.String("Parameter"),
&awsssm.StringParameterProps{
AllowedPattern: aws.String(".*") ,
Description: aws.String("The value Foo"),
ParameterName: aws.String("FooParameter"),
StringValue: aws.String("Foo"),
Tier: awsssm.ParameterTier_ADVANCED,
},
A similar example is in the architecture section
A similar example is in the Lambda Construct section:
Most of the concepts are described with code examples in
See the full source on github.