I have a good amount of parameters so putting them into a file makes more sense than an extremely long blast of text.
I can not seem to figure out how to do this though? It looks like these deploy/package actions do not allow for it but create-stack does?
I was able to achieve that by creating a .properties file for each environment e.g. parameters-dev.properties:
EnvironmentName=dev
key1=value1
key2=value2
and then using command substitution:
aws cloudformation deploy --template-file packaged-template.yaml --parameter-overrides $(cat parameters-dev.properties) --capabilities CAPABILITY_IAM --stack-name test
But definitely it should be more straightforward and deploy command should allow you to just pass a file.
Yea deploy intentionally tries to keep things simple. But it wouldn't hurt to support parameter files in the --parameter-overrides parameter. Can you file an issue under https://github.com/aws/aws-cli? I can get this fixed
Hello there,
Was these feature request implemented? Do the package or deploy commands support a parameters file now?
Thanks,
Yes, This is how I am doing it with Parameter files now. I am not using the deploy command to deploy sam templates but instead, I am using the Create changeset and execute changeset, so that I can pass my Parameter files.
The normal flow of commands:-
Attaching my sample makefile which I use to make deployments from the local machine and the Jenkins also.
`# The CloudFormation template
CFTEMPLATE = CF.yaml
CFTEMPLATENew = package-sam.yaml
CSNAME = changeset
REGION = us-east-1
MNEMONIC = nlsn
MNEMONIC_UPPER = $(strip $(shell echo $(MNEMONIC) | awk '{print toupper($0)}'))
ACCOUNT = non-prod
ACCOUNT_LOWER = $(shell echo $(account) | tr '[A-Z]' '[a-z]')
PARAM_FILE = nlsn-saml-us-east-1-$(ENV_LOWER).json
ENV = $(shell cat $(PARAM_FILE) | jq -r '.[]
| select(.ParameterKey=="Environment") | .ParameterValue')
ENV_LOWER = $(shell echo $(ENV) | tr '[A-Z]' '[a-z]')
RESOURCE_NAME=$(shell cat $(PARAM_FILE) | jq -r '.[]
| select(.ParameterKey=="ServiceName") | .ParameterValue')
RESOURCE_NAME_LOWER = $(shell echo $(RESOURCE_NAME) | tr '[A-Z]' '[a-z]')
RESOURCE_BUCKET=$(shell cat $(PARAM_FILE) | jq -r '.[]
| select(.ParameterKey=="ResourceBucketName") | .ParameterValue')
TEMPLATE_BUCKET=$(shell cat $(PARAM_FILE) | jq -r '.[]
| select(.ParameterKey=="TemplateBucketName") | .ParameterValue')
templateKey=$(shell cat $(PARAM_FILE) | jq -r '.[]
| select(.ParameterKey=="lambdakey") | .ParameterValue')
templateKey_LOWER = $(shell echo $(templateKey) | tr '[A-Z]' '[a-z]')
STACK_NAME=$(RESOURCE_NAME)-$(ENV_LOWER)
LOG_BUCKET=$(shell cat $(PARAM_FILE) | jq -r '.[]
| select(.ParameterKey=="LogBucketName") | .ParameterValue')
listvalues:
@echo $(CFORM)
@echo $(REGION)
@echo $(PARAM_FILE)
@echo $(RESOURCE_NAME)
@echo $(RESOURCE_NAME_LOWER)
@echo $(RESOURCE_BUCKET)
@echo $(TEMPLATE_BUCKET)
@echo $(RESOURCE_NAME)
package:
@echo "Running Package Command : "
@aws cloudformation package --template-file $(CFTEMPLATE)
--s3-bucket $(BucketName) --output-template-file $(CFTEMPLATENew)
--profile $(ACCOUNT)
@echo " "
upload-templatefiles:
@aws s3 cp $(CFTEMPLATE) s3://$(BucketName)/$(RESOURCE_NAME_LOWER)-$(templateKey_LOWER)/$(ENV_LOWER)/ --profile $(ACCOUNT) --acl bucket-owner-full-control
@aws s3 cp $(CFTEMPLATENew) s3://$(BucketName)/$(RESOURCE_NAME_LOWER)-$(templateKey_LOWER)/$(ENV_LOWER)/ --profile $(ACCOUNT) --acl bucket-owner-full-control
@aws s3 cp $(PARAM_FILE) s3://$(BucketName)/$(RESOURCE_NAME_LOWER)-$(templateKey_LOWER)/$(ENV_LOWER)/ --profile $(ACCOUNT) --acl bucket-owner-full-control
createcs: package upload-templatefiles
@echo "Creating new changeset for Updating the Stack"
@aws cloudformation create-change-set --template-url https://s3.amazonaws.com/$(BucketName)/$(RESOURCE_NAME_LOWER)-$(templateKey_LOWER)/$(ENV_LOWER)/$(CFTEMPLATENew)
--stack-name $(STACK_NAME) --capabilities CAPABILITY_IAM --parameters file://$(PARAM_FILE)
--change-set-name $(CSNAME) --change-set-type UPDATE --profile $(ACCOUNT)
@echo " "
createcsnew: package upload-templatefiles
@echo "Creating Intial changeset for creating the Stack"
@aws cloudformation create-change-set --template-url https://s3.amazonaws.com/$(BucketName)/$(RESOURCE_NAME_LOWER)-$(templateKey_LOWER)/$(ENV_LOWER)/$(CFTEMPLATENew) --stack-name $(STACK_NAME)
--capabilities CAPABILITY_IAM --parameters file://$(PARAM_FILE) --change-set-name $(CSNAME) --change-set-type CREATE
--profile $(ACCOUNT)
@echo " "
wait:
@aws cloudformation wait change-set-create-complete --change-set-name $(CSNAME) --stack-name $(STACK_NAME) --profile $(ACCOUNT)
create: createcsnew wait
@echo "Executing First Time Changeset"
@aws cloudformation execute-change-set --change-set-name $(CSNAME) --stack-name $(STACK_NAME) --profile $(ACCOUNT)
update: createcs wait
@echo "Executing the changeset for Updating the Stack"
@echo "If you see errors like ---cannot be executed in its current status of [CREATE_IN_PROGRESS],Please Rerun the Make update command"
@aws cloudformation execute-change-set --change-set-name $(CSNAME) --stack-name $(STACK_NAME) --profile $(ACCOUNT)
@echo "Check the Clouformation Console for updates"
@echo "https://console.aws.amazon.com/cloudformation/home?region=$(REGION)#/stacks?filter=active"
`
@kskory your solution gives me this error An error occurred (ValidationError) when calling the CreateChangeSet operation: Template format error: Every Default member must be a string.
npm ERR! code ELIFECYCLE
I have prod.env file with key value and then my script
sam deploy \
--template-file output.yaml \
--stack-name someStackname \
--capabilities CAPABILITY_IAM \
--parameter-overrides "$(cat prod.env)" \
Environment=$ENV
Most helpful comment
I was able to achieve that by creating a .properties file for each environment e.g. parameters-dev.properties:
EnvironmentName=dev
key1=value1
key2=value2
and then using command substitution:
aws cloudformation deploy --template-file packaged-template.yaml --parameter-overrides $(cat parameters-dev.properties) --capabilities CAPABILITY_IAM --stack-name testBut definitely it should be more straightforward and deploy command should allow you to just pass a file.