Skip to content

Instantly share code, notes, and snippets.

@nackjicholson
Last active March 7, 2022 20:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nackjicholson/5d7d90a49c36b9a61038e6f4e1b33718 to your computer and use it in GitHub Desktop.
Save nackjicholson/5d7d90a49c36b9a61038e6f4e1b33718 to your computer and use it in GitHub Desktop.
Create and cloudformation stack and wait for it to complete.
#!/usr/bin/env bash
STACK_NAME=$1
STACK_PATH=$2
if [ -z "$1" ]
then
echo "No STACK_NAME argument supplied"
exit 1
fi
if [ -z "$2" ]
then
echo "No STACK_PATH argument supplied"
exit 1
fi
STACK_DIR="$(dirname ${STACK_PATH})"
STACK_TMPL="$(basename ${STACK_PATH})"
echo "Creating stack..."
STACK_ID=$( \
aws cloudformation create-stack \
--stack-name ${STACK_NAME} \
--template-body file://${STACK_PATH} \
--capabilities CAPABILITY_IAM \
--parameters file://${STACK_DIR}/parameters.json \
--tags file://${STACK_DIR}/tags.json \
| jq -r .StackId \
)
echo "Waiting on ${STACK_ID} create completion..."
aws cloudformation wait stack-create-complete --stack-name ${STACK_ID}
aws cloudformation describe-stacks --stack-name ${STACK_ID} | jq .Stacks[0].Outputs
#!/usr/bin/env bash
STACK_NAME=$1
STACK_PATH=$2
if [ -z "$1" ]
then
echo "No STACK_NAME argument supplied"
exit 1
fi
if [ -z "$2" ]
then
echo "No STACK_PATH argument supplied"
exit 1
fi
STACK_DIR="$(dirname ${STACK_PATH})"
STACK_TMPL="$(basename ${STACK_PATH})"
echo "Updating stack..."
STACK_ID=$( \
aws cloudformation update-stack \
--stack-name ${STACK_NAME} \
--template-body file://${STACK_PATH} \
--capabilities CAPABILITY_IAM \
--parameters file://${STACK_DIR}/parameters.json \
--tags file://${STACK_DIR}/tags.json \
| jq -r .StackId \
)
echo "Waiting on ${STACK_ID} to update..."
aws cloudformation wait stack-update-complete --stack-name ${STACK_ID}
aws cloudformation describe-stacks --stack-name ${STACK_ID} | jq .Stacks[0].Outputs
@nackjicholson
Copy link
Author

nackjicholson commented Feb 9, 2018

This is how I set them up.

cp create_cfn_stack.sh ~/.local/bin/create_cfn_stack
chmod u+x ~/.local/bin/create_cfn_stack

Use:

create_cfn_stack my-stack-name path/to/my/cloudformation/stack.yml 

Note you need the jq library for this script to run. brew install jq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment