Deploy CloudFormation from cli

This bash script uses aws cli to deploy a stack compared to using the web GUI to create a stack. Main advantage is for automation and repeatability:-

#!/bin/bash
#Written Andrew Stringer 01/03/2021
#Purpose to deploy a cloudformation stack from the cli.
 
STACK_NAME='mystack-a'
TEMPLATE_BODY='file://mystack-a.yaml'
REGION='eu-west-1'
PROFILE=$1
 
TAGS="Key=Name,Value=${STACK_NAME} Key=Build_Method,Value=CloudFormation Key=CostCentre,Value=12345 Key=Owner,Value=MY_ADMIN"
 
echo "Using ${PROFILE}."
 
#Test $1 exists
if [ -z "$PROFILE" ]; then
        echo "Your AWS Profile is not set, using default"
        PROFILE=default
fi
 
# Who are we?
aws sts get-caller-identity --profile ${PROFILE}
 
# Deploy the stack
aws cloudformation update-stack --stack-name ${STACK_NAME} --template-body ${TEMPLATE_BODY} --region ${REGION} --profile ${PROFILE} --capabilities CAPABILITY_NAMED_IAM --tags ${TAGS}
 
aws/aws-deploy_cloudformation_from_cli.txt · Last modified: 15/02/2024 10:09 by andrew