Skip to content

Instantly share code, notes, and snippets.

@brettswift
Created November 4, 2019 15:48
Show Gist options
  • Save brettswift/f1f0febf18ab89fc9fd43670f8af2937 to your computer and use it in GitHub Desktop.
Save brettswift/f1f0febf18ab89fc9fd43670f8af2937 to your computer and use it in GitHub Desktop.
cdk deploy scripting - gathering outputs in a bash script
#!/usr/bin/env bash
# Goal: run cdk apps, parse output like URL's to run a quick smoke test after the deploy
set -e
ACTION='deploy'
NAMESPACE=$(whoami)
CDK_DEPLOY_OUTPUT_FILE='.cdk_deploy_result'
rm -rf ${CDK_DEPLOY_OUTPUT_FILE} # so this script doesn't drive us insane
npm run build
# Deploy and collect output in a file, for parsing after
npx cdk ${ACTION}\
--require-approval never \
-c namespace=${NAMESPACE} \
'Invoice-*' \
2>&1 | tee -a ${CDK_DEPLOY_OUTPUT_FILE}
# Strip .outputs to only outputs.
sed -n -e '/Outputs:/,/^$/ p' ${CDK_DEPLOY_OUTPUT_FILE} > .outputs
API_GW_URL=$(awk -F " " '/ApiGatewayUrl/ { print $3 }' .outputs)
API_KEY_RESOURCE_ID=$(awk -F " " '/ApiKey1/ { print $3 }' .outputs)
API_KEY=$(aws apigateway get-api-key --api-key ${API_KEY_RESOURCE_ID} --include-value | jq -r '.value')
# QA the thing
result=$(curl -H "x-api-key: ${API_KEY}" ${API_GW_URL}/api/healthcheck)
echo ${result}
echo ${result} | jq '.[0]' | grep Version
echo "Success!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment