Skip to content

tsukiy0's blog

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 stack
    • KEY is the name of the output key
STACK_OUTPUTS=aws cloudformation describe-stacks --stack-name ${STACK_NAME} --query Stacks[0].Outputs --output json
VALUE=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})

tsukiy0