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

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

Closed
pcx opened this issue May 7, 2018 · 2 comments
Closed

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

pcx opened this issue May 7, 2018 · 2 comments

Comments

@pcx
Copy link

pcx commented May 7, 2018

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].

@sanathkr
Copy link
Contributor

sanathkr commented May 8, 2018

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

@sanathkr sanathkr closed this as completed May 8, 2018
@pcx
Copy link
Author

pcx commented May 9, 2018

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

qingchm pushed a commit to qingchm/aws-sam-cli that referenced this issue Sep 17, 2021
* Added More Envs to gitignore

* Fixed Typo

* Refactoring commands._utils.resources to lib.utils.resources

* Fixed PyLint Import Issues

* Added DefinitionCodeTrigger and StepFunctionCodeTrigger

* Refactored APIGW and SFN CodeTriggers

* Fixed Error Handling

* Updated Comments

* Removed MissingDefinitionUri

* Merged UriNotFoundException into MissingLocalDefinition

* Added Exception Test for DefinitionCodeTrigger

* Fixed PyLint Import Order Issues

* Imported Ordering for Tests

* Added Logging for None Returns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants