Skip to content

Instantly share code, notes, and snippets.

@brettswift
Created November 4, 2019 15:48
Show Gist options
  • Select an option

  • Save brettswift/f1f0febf18ab89fc9fd43670f8af2937 to your computer and use it in GitHub Desktop.

Select an option

Save brettswift/f1f0febf18ab89fc9fd43670f8af2937 to your computer and use it in GitHub Desktop.

Revisions

  1. brettswift created this gist Nov 4, 2019.
    34 changes: 34 additions & 0 deletions blaster.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/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!"