-
Notifications
You must be signed in to change notification settings - Fork 73
Conversation
Add the deploy target to the Makefile to make it easier to deploy the application to a dev environment on CloudFormation. Add the docs for the new target to the README.md file. Update the README.md instructions so that the Markdown validator agrees with the styling.
- Improve feedback while running the commands - Add `sam validate` on the template before deploying
@heitorlessa i have used this setup in a small poc project and there i had the need to customize the Makefile to support custom parameters but the deployment process is something generic so i build something like this: # Include project specific targets
EXTENSIONS=$(shell test -f Makefile.extension && echo 'Makefile.extension')
include $(EXTENSIONS)
...OTHER TARGETS...
_package_template:
$(info [+] Package template.yaml to packaged.yaml and upload the artifacts to $(BUCKET) with $(CAPABILITIES))
@aws cloudformation package \
--template-file $(BASE)/template.yaml \
--output-template-file $(BASE)/packaged.yaml \
--s3-bucket ${BUCKET} > /dev/null 2>&1
_validate_template: _package_template
$(info [+] Validate template.yaml)
@aws cloudformation validate-template \
--template-body file://$(BASE)/packaged.yaml > /dev/null ; test "$$?" -eq 0 && echo '[+] Template is valid' || (echo '[!] Template is invalid!' && exit 1)
_deploy_template: _validate_template
$(info [+] Deploy packaged.yaml -- This may take a while...)
@aws cloudformation deploy \
--no-fail-on-empty-changeset \
--template-file $(BASE)/packaged.yaml \
--stack-name $(NAME) \
$($$(MAKE) _get_stack_capabilities) \
$($$(MAKE) _get_stack_parameters) \
; test "$$?" -eq 0 && echo '[+] Template has been deployed' || (echo '[!] Deployment of the template failed' && exit 1) And then a NAME = my-stack-name
CAPABILITIES = CAPABILITY_IAM
CODE_COVERAGE = 95
# Tags
COST_CENTER=Engineering
PRODUCT=Internal
ENVIRONMENT=Development
OWNER=Nr.18
_get_stack_capabilities:
@echo --capabilities $(CAPABILITIES)
_get_stack_parameters:
@echo --parameter-overrides \
CostCenter=$(COST_CENTER) \
Product=$(PRODUCT) \
Environment=$(ENVIRONMENT) \
Owner=$(OWNER) The general idea behind this is that the Makefile stays the same and all customizations are done in the Should i include it? |
I like the idea to have a sample for cloudformation deploy in a makefile. I discussed with @heitorlessa about the idea to have some kind of advanced templates or examples. But we agreed to focus on the basics to enable others to build even more (advanced) solutions and own cookiecutter based setup templates (like the one with your Makefile extension). Nevertheless I would like to have _*_template in the makefile, but without the Makefile.extension. This could be better documented as an advanced example for specific use cases. |
@heitorlessa i think we can close this one in favor of #9 right? |
Yep, I'd say so. Let's close this as this would add additional complexity that people could easily get into trouble. |
No issue available
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.