Aws-sam-cli: sam local --env-vars parameter does not work

Created on 8 Jul 2018  路  1Comment  路  Source: aws/aws-sam-cli

Env is not passed to Lambda funtion.

Description:

Steps to reproduce the issue:

  1. sam init -r nodejs8.10 to generate template.yaml with the following in it:
Resources:
    HelloWorldFunction:
        Type: AWS::Serverless::Function
        Properties:
            CodeUri: hello_world/
            Handler: app.lambda_handler
            Runtime: nodejs8.10
            Environment: 
                Variables:
                    PARAM1: VALUE
            Events:
                HelloWorld:
                    Type: Api
                        Path: /hello
                        Method: get
  1. Change app.js to be:
exports.lambda_handler = async (event, context, callback) => {
    callback(null, {
        'statusCode': 200,
        'body': JSON.stringify(process.env)
    })
};
  1. create file env.json
{
  "HelloWorldFunction":{
    "MY_TEST_ENV_PROP": "value"
  }
}
  1. Run:
MY_OTHER_TEST_ENV_PROP="OTHER_VALUE" sam local start-api --debug --port 8000 --env-vars env.json
  1. Open http://127.0.0.1:8000/hello in browser to see result.

Observed result:
No MY_TEST_ENV_PROP and MY_OTHER_TEST_ENV_PROP listed. However the PARAM1 from the template.yaml - is.

Expected result:
process.env.MY_TEST_ENV_PROP and process.env.MY_OTHER_TEST_ENV_PROP should exist and be equal to appropriate values as described in https://docs.aws.amazon.com/lambda/latest/dg/test-sam-cli.html

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
Mac,
Python 2.7.10

Output of sam --version:
$ sam --version
SAM CLI, version 0.4.0

Most helpful comment

@milashenko I think the document may be misleading. The shell and file vars you can define when running the cli only override the ones already declared in your template file. Only PARAM1 in your example then.

>All comments

@milashenko I think the document may be misleading. The shell and file vars you can define when running the cli only override the ones already declared in your template file. Only PARAM1 in your example then.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicosuave picture nicosuave  路  44Comments

kaukas picture kaukas  路  24Comments

burck1 picture burck1  路  45Comments

sanathkr picture sanathkr  路  37Comments

oldnerd picture oldnerd  路  25Comments