Last active
August 7, 2024 10:37
-
-
Save huevos-y-bacon/5139fef765fedaed10ae4468f4cd0cd8 to your computer and use it in GitHub Desktop.
AWS CloudFormation - Makefile template
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
AWS_ARGS:=--profile $(AWS_PROFILE) --region $(AWS_REGION) | |
STACK_NAME:=some-infra | |
TEMPLATE_FILE:=some-infra.yaml | |
OWNER:="My Team" | |
CFN_TAGS:=--tags \ | |
Key=Owner,Value='$(OWNER)' \ | |
Key=DeployedBy,Value=CloudFormation | |
# Comment/Uncomment/Add as needed; uncommented lines must be contiguous | |
# PARAMS:= --parameters \ | |
# ParameterKey=xxx,ParameterValue=$(xxx) \ | |
# ParameterKey=yyy,ParameterValue=$(yyy) \ | |
# ParameterKey=zzz,ParameterValue=$(zzz) \ | |
create-stack: | |
@echo "Create Stack : $(STACK_NAME)" | |
@echo "Template : $(TEMPLATE_FILE)" | |
@aws cloudformation create-stack \ | |
--stack-name $(STACK_NAME) $(PARAMS) $(CFN_TAGS) \ | |
--template-body file://$(TEMPLATE) $(AWS_ARGS) | |
update-stack: | |
@echo "Update Stack : $(STACK_NAME)" | |
@echo "Template : $(TEMPLATE_FILE)" | |
@echo "Change set : $(STACK_NAME)-$(shell date +%s)" | |
@aws cloudformation create-change-set \ | |
--stack-name $(STACK_NAME) $(PARAMS) $(CFN_TAGS) \ | |
--change-set-name $(STACK_NAME)-$(shell date +%s) \ | |
--template-body file://$(TEMPLATE) $(AWS_ARGS) | |
force-update-stack: | |
@echo "Update Stack : $(STACK_NAME)" | |
@echo "Template : $(TEMPLATE_FILE)" | |
@aws cloudformation update-stack \ | |
--stack-name $(STACK_NAME) $(PARAMS) $(CFN_TAGS) \ | |
--template-body file://$(TEMPLATE) $(AWS_ARGS) | |
describe-stack-events: | |
@echo "Stack Events : $(STACK_NAME)" | |
@aws cloudformation describe-stack-events \ | |
--stack-name $(STACK_NAME) $(AWS_ARGS) | |
output-stack: | |
@echo "Stack Outputs : $(STACK_NAME)" | |
@aws cloudformation describe-stacks \ | |
--stack-name $(STACK_NAME) $(AWS_ARGS) \ | |
--query '.Stacks[].Outputs' | |
delete-stack: | |
@echo "Deleting Stack : $(STACK_NAME)" | |
@aws cloudformation delete-stack \ | |
--stack-name $(STACK_NAME) $(AWS_ARGS) | |
wait-delete-stack: | |
@echo "Waiting for Deletion of Stack : $(STACK_NAME)" | |
@aws cloudformation wait stack-delete-complete \ | |
--stack-name $(STACK_NAME) $(AWS_ARGS) | |
wait-create-stack: | |
@echo "Waiting for Creation of Stack : $(STACK_NAME)" | |
@aws cloudformation wait stack-create-complete \ | |
--stack-name $(STACK_NAME) $(AWS_ARGS) | |
validate-template: | |
@echo "Validate Template : $(TEMPLATE)" | |
@aws cloudformation validate-template \ | |
--template-body file://$(TEMPLATE) $(AWS_ARGS) --out yaml | |
describe-stack-status: | |
@echo "Stack : $(STACK_NAME)" | |
@aws cloudformation describe-stacks \ | |
--stack-name $(STACK_NAME) $(AWS_ARGS) \ | |
--query 'Stacks[0].StackStatus' \ | |
--output text | |
create-stack-and-wait: create-stack wait-create-stack describe-stack-status | |
delete-stack-and-wait: delete-stack wait-delete-stack describe-stack-status | |
help: | |
@printf "Make sure AWS_PROFILE, AWS_REGION are exported into the shell \n"; | |
.DEFAULT_GOAL := help | |
PWD:=$(shell pwd) | |
TS:=$(shell /bin/date "+%s") | |
TEMPLATE:=$(PWD)/$(TEMPLATE_FILE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment