Aws-cli: aws lambda update-function-configuration --environment key/value pair only works for one key/value

Created on 5 Jun 2017  路  10Comments  路  Source: aws/aws-cli

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

closing-soon guidance

Most helpful comment

@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"}}}'

All 10 comments

@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"}}}'

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}\"",

+ 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?

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

@megamindbrian looks like now documentation is correct

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.

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"}}'

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

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.

Was this page helpful?
0 / 5 - 0 ratings