Skip to content

Environment variables file doesn't work with start-api #381

Closed

Description

@pcx

My template.yaml looks like this:

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
  TestFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: test.handler
      Runtime: nodejs8.10
      Events:
        GetSyncObject:
          Type: Api
          Properties:
            Path: /test
            Method: get

The env.json looks like this:

{
    "TestFunction": {
        "ENV_NAME": "development",
        "DATABASE_URL": "http://dynamodb:8000/"
    }
}

The test.js file looks like this:

module.exports.handler = (event, context, callback) => {
  console.log(process.env);
};

I am running the command as:
sam local start-api --env-vars env.json

The out put in the terminal does not show the env vars from the file specified above. I am using OSX and [email protected].

Activity

  1. sanathkr commented on May 8, 2018

    @sanathkr

    You need to define the Environment section in the Function for the envars to show up during execution. Only the variables in the Environment section will be read from the file and show up in the execution

  2. pcx commented on May 9, 2018

    @pcx
    Author

    @sanathkr This was not immediately apparent from the README. Thanks for clearing that up!

  3. added a commit that references this issue on Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions