Get CloudFormation stack outputs
March 12, 2021
Often times after a deployment you need to get the outputs of a CloudFormation stack, e.g. for integration testing.
The script requires:
awscli
jq
- Environment
STACK_NAME
is the name of the stackKEY
is the name of the output key
STACK_OUTPUTS=aws cloudformation describe-stacks --stack-name ${STACK_NAME} --query Stacks[0].Outputs --output jsonVALUE=echo $STACK_OUTPUTS | jq --arg KEY ${KEY} '.[] | select(.OutputKey==$KEY) | .OutputValue'
Alternatively as a function:
get_cfn_output() {echo $(aws cloudformation describe-stacks --stack-name ${1} --query "Stacks[0].Outputs[?OutputKey==\`${2}\`].OutputValue" --output text)}VALUE=$(get_cfn_output ${STACK_NAME} ${KEY})