Skip to content

Instantly share code, notes, and snippets.

@racheliurui
Last active November 14, 2023 07:39
Show Gist options
  • Save racheliurui/0fcb3be5ce8478b02029e2a78dd41d50 to your computer and use it in GitHub Desktop.
Save racheliurui/0fcb3be5ce8478b02029e2a78dd41d50 to your computer and use it in GitHub Desktop.
CDK Construct Cookie Cutter

Readme

CDK cookie cutter to accelerate development.

Init the construct

  • construct should be in root folder to support smooth npm install git+ssh
  • cdk init must run from an empty folder

Step 1, create construct template locally first

Use VSCode, from terminal set the right params and folder context

cd ~/github
# update the construct name
constructName=<cdk-construct-xxxxxx> #naming convention for easier locate

Initialize the CDK construct

mkdir ${constructName}
cd ${constructName}
cdk init lib --language=typescript

Update doco.

#replace README.txt
curl -L https://gist.githubusercontent.com/racheliurui/0fcb3be5ce8478b02029e2a78dd41d50/raw/CDK-Construct.md > README.md
#add architecture diagram
touch ${constructName}.drawio.png
echo "# Architecture" >> README.md
echo '![architecture]'"(${constructName}.drawio.png)" >> README.md

prepare git repo

git init
git add -A
git commit -m "init"

Step 2, create repo match with construct Name and push local code

Step 3, build construct till happy

Build the construct locally

npm install
npm run build

Use the construct

run the command from the other repo where you need to use the construct

npm install git+ssh://[email protected]:racheliurui/${constructName}.git 

References

https://fourco.nl/blogs/writing-your-own-aws-cdk-constructs/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment