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

add support for lambda env vars in invoke local #2757

Merged
merged 1 commit into from
Nov 21, 2016
Merged

Conversation

eahefnawy
Copy link
Member

What did you implement:

Add support for lambda env vars in invoke local. Any env vars that you set in serverless.yml will be available when you run sls invoke local without having to load them manually.

How did you implement it:

Added a new loadEnvVars() method to invoke local that runs before running the function.

How can we verify it:

serverless.yml

service: serverless-local-env-vars

provider:
  name: aws
  cfLogs: true
  environment:
    hello: world

functions:
  hello:
    environment:
      hello2: world2
      hello: worldOverwritten
    handler: handler.hello

handler.js:

module.exports.hello = (event, context, callback) => {
  console.log(process.env.hello)
  console.log(process.env.hello2)
  const body = {
    message: 'Go Serverless v1.0! Your function executed successfully!',
    input: event,
  };

  const response = {
    statusCode: 200,
    headers: {
      'custom-header': 'Custom header value',
    },
    body: JSON.stringify(event),
  };

  return  callback(null, event);
};

run serverless invoke local -f hello and see the env vars values in the console

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config/commands/resources
  • Enable "Allow edits from maintainers" for this PR
  • Change ready for review message below

Is this ready for review?: YES

@eahefnawy eahefnawy added this to the 1.2 milestone Nov 21, 2016
@eahefnawy eahefnawy self-assigned this Nov 21, 2016
@nikgraf
Copy link
Contributor

nikgraf commented Nov 21, 2016

Reviewing now …

@nikgraf
Copy link
Contributor

nikgraf commented Nov 21, 2016

@eahefnawy just tested it with new examples and works like a charm

@nikgraf nikgraf merged commit 63d13a4 into master Nov 21, 2016
@nikgraf nikgraf deleted the local-env-vars branch November 21, 2016 11:35
@jeremydaly
Copy link
Contributor

I have ARNs from Cloudformation outputs populating my environment variables in my Serverless.yml config. Running invoke local loads the environment variable, but populates it with the static JSON instead of the correct output.

  environment:
    NOTIFICATION_TOPIC: { "Ref": "notifications" }

@pmuens
Copy link
Contributor

pmuens commented Nov 27, 2016

@jeremydaly thanks for reporting 👍

Could you open up a new issue for that?

/cc @eahefnawy

@mrowles
Copy link

mrowles commented Dec 1, 2016

Lovely work :)

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

Successfully merging this pull request may close these issues.

None yet

5 participants