Created
October 13, 2018 20:12
-
-
Save spacekitcat/92d58f3b7b0827715931ede0ab59a512 to your computer and use it in GitHub Desktop.
Deletes, packages and redeploys a CloudFormation stack. Convenience for scripts for debugging automatic deploys.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# October 2018. | |
# Written by Lisa Burton. | |
# Provided under the terms of the MIT license. | |
STACK_NAME='<<< YOUR_CLOUD_FORMATION_STACK_NAME >>>' | |
SAM_INPUT_TEMPLATE='<<< YOUR_SAM_FILE_HERE >>>' | |
SAM_OUTPUT_TEMPLATE='outputSamTemplate.yaml' | |
SAM_S3_BUCKET='<<< YOUR_S3_BUCKET_NAME >>>' | |
function deleteStack() | |
{ | |
printf "INFO: Deleting stack \`%s\` ..." $1 | |
aws cloudformation delete-stack --stack-name $1 | |
if [ "$?" -eq 0 ]; then | |
printf "Done. \n" | |
else | |
printf "\nWARN: Couldn't delete stack \`%s\`, probably because it doesn't exist.\n" $1 | |
fi | |
} | |
function createSamPackage() | |
{ | |
printf "INFO: Creating SAM package ...\n" | |
aws cloudformation package --template-file $1 --output-template-file $2 --s3-bucket $3 | |
if [ $? -eq 0 ] | |
then | |
printf "Done. \n" | |
else | |
printf "\nFATAL: Couldn't create SAM package.\n" | |
exit -1 | |
fi | |
} | |
function deploySamPackage() | |
{ | |
printf "INFO: Deploying SAM stack ...\n" | |
aws cloudformation deploy --template-file $1 --stack-name $2 --capabilities CAPABILITY_NAMED_IAM | |
if [ $? -eq 0 ] | |
then | |
printf "Done. \n" | |
else | |
printf "\nFATAL: Couldn't deploy SAM package.\n" | |
exit -1 | |
fi | |
} | |
deleteStack $STACK_NAME | |
createSamPackage $SAM_INPUT_TEMPLATE $SAM_OUTPUT_TEMPLATE $SAM_S3_BUCKET | |
deploySamPackage $SAM_OUTPUT_TEMPLATE $STACK_NAME | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment