New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sam deploy should accept parameter file just like aws cloudformation *-stack #2054
Comments
Why not use the samconfig.toml file? https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html |
I am trying to set a parameter that is specified in the template. There is no hint in the documentation that this should be possible but following your suggestion it tried the following: Parameter defined in the template:
Updated
The deploy works but doesn't honor the new parameter. Looking at the structure of the config I also tried this line:
Which breaks the deployment entirely:
And this:
And this:
both of which do work but are really hard to maintain if you have more than a couple parameters or if your parameters need complex quoting. In fact it turns out that if you were to enter the data interactively as a result of using
|
As @rudpot mentioned, the following
+1 for a simpler approach. |
work around until a file can be used is to wrap w/ shell or make ...
--parameter-overrides \
DBUsername=$(DBUSER) \
DBPassword=\"$(shell get-db-pass)\" \
Subnets=$(SUBNETS) \
VpcId=$(VPC_ID) load up a config file with k/v pairs and use
|
We use a similar pattern to @rojomisin but use a standard environment variable file format. .sam-params
Then in our Makefile, we sam deploy --parameter-overrides $(shell cat .sam-params) |
I've used the above workaround for now, but it would be great to get some consistency with cloudformation in this regard. |
#2253 proposes parameter overrides should get their own section in |
The trick by @jveldboom works just as well in a shell-script, except with |
I'm using jq as an alternative.... Having the following structure // parameters.json
I can do
The good thing is that file can be shared with Cloudformation templates with:
|
if |
I need to use a SAM parameter to upload a private RSA key in PEM format to AWS SecretsManager. I've been trying all kinds of things on the CLI (including everything above) to get this to work. I ended up giving up and writing this workaround in my import base64
import boto3
# AWS CLI can't (easily) take params with newlines or spaces. Thus, we base64 encode our RSA PEM
# to make it single line before we upload it to Secrets Manager. See docs/design-notes.md
def get_lighthouse_rsa_key(awsSecretArn): # pragma: no cover
smClient = boto3.client("secretsmanager")
base64EncodedPem = smClient.get_secret_value(SecretId=awsSecretArn)["SecretString"]
resultBytes = base64.b64decode(base64EncodedPem)
return resultBytes.decode() I would be thankful if the SAM CLI maintainers incorporate @whereisaaron 's suggestion above on April 5th, 2021. Note: Another part of the problem plaguing with (most) PEM files is the fact that CloudFormation parameters can be 4096 bytes, max. To support PEM files (at least those that are more than 4096 bytes) CloudFormation would need to provide an attribute to each parameter to override the 4096 byte max. Perhaps an attribute like |
I resolved this scenario using options below:
Or
|
Line breaks didn't let me use this option Result:
I had to change it to this SAM_PARAMETERS=$( cat params.json | jq -r '[ .[] | "\(.ParameterKey)=\(.ParameterValue)" ] | join(" ")' ) Result:
|
I would love to see SAM having a built-in easier way to do this. It becomes a maintenance hell unless the developers implement workarounds like @HFR1994 and @jveldboom suggested. |
Perhaps an easier workaround than custom wrapper scripts, is to use TOML's multiline support in the [default.deploy.parameters]
parameter_overrides = """
ApplicationName='Foo'
ApplicationKey='Bar'
""" Which it seems to parse just fine during
Although I agree putting it in a separate file would look cleaner, at least this way it remains the default |
@JaimySmets as mentioned in #2253 (comment) it also works with a list parameter_overrides=[
"ApplicationName=Foo",
"ApplicationKey=Bar"
] either way it doesn't solve for the parameters needing to be managed separately from the |
How should configure it in a pipeline without load credentials to git if I need the value of the Parameters in build phase, because the lambda download an private pypi package which require authentication? |
This worked great for me until I started trying to use parameters whose values were lists:
|
Description:
I would like to store configuration is version control and make deployment steps immutable. Instead of changing parameter overrides on the command line I would like to provide template parameters from a file.
There is an idiom for this in
aws cloudformation create-stack --parameters file://
.Steps to reproduce the issue:
sam deploy --parameter-overrides file://params.json
Observed result:
Expected result:
The text was updated successfully, but these errors were encountered: