Skip to content

Instantly share code, notes, and snippets.

@guillaume
Created June 9, 2017 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guillaume/9b4e252f75fe3fa0c7eb9d570bf0c259 to your computer and use it in GitHub Desktop.
Save guillaume/9b4e252f75fe3fa0c7eb9d570bf0c259 to your computer and use it in GitHub Desktop.
serverless offline bug with env variables
"use strict";
const printFoo = (event, context, callback) => {
const response = {
statusCode: 200,
body: JSON.stringify(process.env.FOO)
};
callback(null, response);
// Use this code if you don't use the http event with the LAMBDA-PROXY integration
// callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event });
};
module.exports.foo = printFoo;
module.exports.bar = printFoo;
module.exports.baz = printFoo;
service: my-service
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"
plugins:
- serverless-offline
provider:
name: aws
runtime: nodejs6.10
environment:
FOO: foo
# you can define service wide environment variables here
functions:
foo:
handler: handler.foo
events:
- http:
method: get
path: /foo
bar:
handler: handler.bar
events:
- http:
method: get
path: /bar
environment:
FOO: bar
baz:
handler: handler.baz
events:
- http:
method: get
path: /baz
environment:
FOO: baz
curl 'http://localhost:3000/foo'
curl 'http://localhost:3000/bar'
curl 'http://localhost:3000/baz'
@guillaume
Copy link
Author

should print

$ sh test.sh
"foo""bar""baz"

@guillaume
Copy link
Author

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