Skip to content
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

aws lambda update-function-configuration --environment key/value pair only works for one key/value #2638

Closed
tleyden opened this Issue Jun 5, 2017 · 10 comments

Comments

Projects
None yet
@tleyden
Copy link

tleyden commented Jun 5, 2017

This doesn't work:

aws lambda update-function-configuration --function-name lambda-func-name --environment Variables={FOO=bar,BAZ=blah}

Whereas this works:

aws lambda update-function-configuration --function-name lambda-func-name --environment '{"Variables":{"FOO":"bar", "BAZ":"blah"}}'

Other folks have reported the same issue: https://gist.github.com/andywirv/f312d561c9702522f6d4ede1fe2750bd

@JordonPhillips

This comment has been minimized.

Copy link
Member

JordonPhillips commented Jun 5, 2017

@tleyden you probably need to just encapsulate it in quotes, which worked for bash:

$ aws lambda update-function-configuration --function-name lambda-func-name --environment "Variables={FOO=bar,BAZ=blah}" --debug
2017-06-05 14:37:34,861 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/1.11.95 Python/3.5.1 Darwin/15.6.0 botocore/1.5.58
2017-06-05 14:37:34,862 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['lambda', 'update-function-configuration', '--function-name', 'lambda-func-name', '--environment', 'Variables={FOO=bar,BAZ=blah}', '--debug']
[ ... ]
2017-06-05 14:37:34,921 - MainThread - botocore.endpoint - DEBUG - Making request for OperationModel(name=UpdateFunctionConfiguration) (verify_ssl=True) with params: {'method': 'PUT', 'context': {'client_config': <botocore.config.Config object at 0x1108b8668>, 'has_streaming_input': False, 'client_region': 'us-west-2', 'auth_type': None}, 'url_path': '/2015-03-31/functions/lambda-func-name/configuration', 'body': b'{"Environment": {"Variables": {"FOO": "bar", "BAZ": "blah"}}}', 'query_string': {}, 'headers': {'User-Agent': 'aws-cli/1.11.95 Python/3.5.1 Darwin/15.6.0 botocore/1.5.58'}, 'url': 'https://lambda.us-west-2.amazonaws.com/2015-03-31/functions/lambda-func-name/configuration'}
[ ... ]

As you can see the body was correctly set to 'body': b'{"Environment": {"Variables": {"FOO": "bar", "BAZ": "blah"}}}'

@fibo

This comment has been minimized.

Copy link

fibo commented Dec 19, 2017

I used the npm script below and it works, thanks to @JordonPhillips for the correct syntax

  "set_environment": "aws lambda update-function-configuration --region us-east-1 --profile bitstamp --function-name ${npm_package_name} --environment \"Variables={BITSTAMP_CUSTOMERID=$BITSTAMP_CUSTOMERID,BITSTAMP_APISECRET=$BITSTAMP_APISECRET,BITSTAMP_APIKEY=$BITSTAMP_APIKEY}\"",
@megamindbrian

This comment has been minimized.

@Spechal

This comment has been minimized.

Copy link

Spechal commented May 16, 2018

+ aws lambda update-function-configuration --region us-east-1 --function-name dev-nodejs-test --description 'Sends test SNS message for pipeline validity' --environment '{"Variables": { "A": "This is the letter A.", "B": "This is the letter B." } }' An error occurred (ValidationException) when calling the UpdateFunctionConfiguration operation: 1 validation error detected: Value at 'environment.variables' failed to satisfy constraint: Map keys must satisfy constraint: [Member must satisfy regular expression pattern: [a-zA-Z]([a-zA-Z0-9_])+]

JSON is valid, no commas in Map keys... any thoughts?

@Spechal

This comment has been minimized.

Copy link

Spechal commented May 16, 2018

Figured it out ... can't have a single letter environment variable. Helps if I read the regex...

@fibo

This comment has been minimized.

Copy link

fibo commented May 17, 2018

@megamindbrian looks like now documentation is correct

@codeinaire

This comment has been minimized.

Copy link

codeinaire commented Sep 19, 2018

Nah, the documentation isn't correct. It has either the double quotes or it doesn't. The way that worked for me was with the double quotes here. Whereas this way didn't work, it's without the double quotes.

@gilzow

This comment has been minimized.

Copy link

gilzow commented Dec 10, 2018

Can someone PLEASE update the docs on the website and internal for update-function-configuration as to how environmental variables need to be structured?

According to both

 --environment (structure)
          The parent object that  contains  your  environment's  configuration
          settings.

       Shorthand Syntax:

          Variables={KeyName1=string,KeyName2=string}

But that will result in an error message
Unknown options: Variables=KeyName2=string
for anything past the first key+val pair.

The only method that works is the one @tleyden noted
'{"Variables":{"KeyName1":"string","KeyName2":"string"}}'

@diehlaws diehlaws added guidance and removed question labels Jan 4, 2019

@BouchaaraAdil

This comment has been minimized.

Copy link

BouchaaraAdil commented Jan 15, 2019

this worked for me aws lambda update-function-configuration --function-name ${FUNCTION_NAME} --environment "Variables={"AB_BRANCH_NAME"=$BR_NAME, "DISTRIBUTION_ID"="xxxxxxx"}"

@ffosb22

This comment has been minimized.

Copy link

ffosb22 commented Mar 13, 2019

I copy pasted this exact string for --environment: '{"Variables":{"KeyName1":"string","KeyName2":"string"}}' and I'm still having the same parsing problem.

While it works locally, it doesn't work on my Jenkins slave. It gives the same Unknown Options error that others are experiencing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.