Instead of wrapping the cdk deploy
command in a bash script I find it more convenient to add a pre
and post
deployment script under a cdk_hooks.sh
file and call it before and after the CDK deployment command via the cdk.json
file. In this way you can keep using the cdk deploy
command without calling custom scripts manually.
cdk.json
{
"app": "sh cdk_hooks.sh pre && npx ts-node bin/stacks.ts && sh cdk_hooks.sh post"
,
"context": {
"@aws-cdk/core:enableStackNameDuplicates": "true",
"aws-cdk:enableDiffNoFail": "true"
}
}
and cdk_hooks.sh
#!/bin/bash
PHASE=$1
case "$PHASE" in
pre)
# Do something
;;
post)
# Do something
;;
*)
echo "Please provide a valid cdk_hooks phase"
exit 64
esac