Search code examples
linuxaws-lambdaaws-cli

Passing a JSON file as environment variable to aws lambda update-function-configuration cli


I am looking for a solution to pass a JSON file as environment variable to aws lambda update-function-configuration cli.

for example:

aws lambda update-function-configuration --function-name "test" --environment var.json

and the variable JSON file would be:

{
  "Variables": {"string": "string",
    ...}
}

So, basically looking for a dynamic solution to insert environment variables to Lambda function via CLI.

Thanks in advance


Solution

  • Assuming the content of the var.json is as follow:

    {
        "key1":"value1",
        "key2":"value2"
    }
    

    Then you can run the aws cli like this:

    aws lambda update-function-configuration --function-name "test" --environment "{\"Variables\":`cat var.json`}"