Serverless-application-model: Is there no way to specify a parameters file?

Created on 23 Mar 2017  路  5Comments  路  Source: aws/serverless-application-model

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?

typfeature

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 test

But definitely it should be more straightforward and deploy command should allow you to just pass a file.

All 5 comments

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:-

  1. aws cloudformation package --template-file $(CFTEMPLATE) --s3-bucket $(BucketName) --output-template-file $(CFTEMPLATENew) --profile $(ACCOUNT)
  2. 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)
  3. aws cloudformation execute-change-set --change-set-name $(CSNAME) --stack-name $(STACK_NAME) --profile $(ACCOUNT)

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

AWS Region

REGION = us-east-1

Mnemonic is for cross company support

MNEMONIC = nlsn
MNEMONIC_UPPER = $(strip $(shell echo $(MNEMONIC) | awk '{print toupper($0)}'))

The Account, i.e sandbox | non-prod | prod

ACCOUNT = non-prod
ACCOUNT_LOWER = $(shell echo $(account) | tr '[A-Z]' '[a-z]')
PARAM_FILE = nlsn-saml-us-east-1-$(ENV_LOWER).json

The Environment, i.e dev|qa|uat|prod

ENV = $(shell cat $(PARAM_FILE) | jq -r '.[]
| select(.ParameterKey=="Environment") | .ParameterValue')
ENV_LOWER = $(shell echo $(ENV) | tr '[A-Z]' '[a-z]')

Resource Name

CloudFormation S3 Buckets

RESOURCE_NAME=$(shell cat $(PARAM_FILE) | jq -r '.[]
| select(.ParameterKey=="ServiceName") | .ParameterValue')
RESOURCE_NAME_LOWER = $(shell echo $(RESOURCE_NAME) | tr '[A-Z]' '[a-z]')

CloudFormation S3 Buckets

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]')

CloudFormation Stack Name

STACK_NAME='$(RESOURCE_NAME)'

STACK_NAME=$(RESOURCE_NAME)-$(ENV_LOWER)
LOG_BUCKET=$(shell cat $(PARAM_FILE) | jq -r '.[]
| select(.ParameterKey=="LogBucketName") | .ParameterValue')

lists all available targets

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"

validate:

@echo "Validating the Stack for errors"

@aws cloudformation validate-template --template-url https://s3.amazonaws.com/$(RESOURCE_BUCKET)/$(ENVIRONMENT)/$(CFTEMPLATENew)

@echo " "

`

@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 
Was this page helpful?
0 / 5 - 0 ratings

Related issues

charsleysa picture charsleysa  路  3Comments

PMudra picture PMudra  路  4Comments

zeroastro picture zeroastro  路  3Comments

vinkris picture vinkris  路  3Comments

feinstein picture feinstein  路  3Comments