-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Hi there!
I recently had to switch laptops at work and now for some reason, something that was working before, is now not.
In my project I have a few functions and one of them calls another, which works fine, however the called function only has the environement variables from the previous function, and non of its own, however if I call each lambda through it's own serverless offline URL, all the appropiate environment variables are working.
Heres a small example I created to make it simpler to understand:
serverless.yml
service: local-test
provider:
name: aws
region: eu-west-1
runtime: nodejs12.x
stage: ${opt:stage, 'local'}
plugins:
- serverless-offline-lambda
- serverless-offline
functions:
function_one:
handler: one.handler
events:
- http:
path: /one
method: GET
environment:
ONE: 'Hey this is the first'
function_two:
handler: two.handler
events:
- http:
path: /two
method: GET
environment:
TWO: 'Hey this is the Second'
Function One:
const AWS = require("aws-sdk");
AWS.config.update({ region: 'eu-west-1' });
const lambdaObject = new AWS.Lambda({
apiVersion: "2015-03-31",
region: 'eu-west-1',
accessKeyId: 'root',
secretAccessKey: 'root',
sslEnabled: false,
endpoint: new AWS.Endpoint('http://localhost:4000')
});
exports.handler = async event => {
console.log(process.env.ONE);
console.log(process.env.TWO);
lambdaObject.invoke({
FunctionName: 'function_two',
InvocationType: "RequestResponse", // 'RequestResponse' for sync or "Event" for async
Payload: JSON.stringify({})
})
.promise()
.then(data => {
console.log('Worked');
})
.catch(error => {
console.log('Failed', error);
});
}
Function Two
exports.handler = async event => {
console.log(process.env.ONE);
console.log(process.env.TWO);
}
If I call Function One through its URL (http://localhost:3000/one) I get Hey this is the first on the console, if I call Function Two through its URL (http://localhost:3000/two) I get Hey this is the first - Hey this is the Second.
However when calling Function One through its URL, it also of course triggers function two, so the console actually reads:
Serverless: GET /one (λ: function_one)
Hey this is the first
undefined
Serverless: Invoke (λ: function_two)
Hey this is the first
undefined
Worked
Which is wrong as function_two should say Hey this is the second, like it does when invoking it through the URL directly.
I swear this was working before i switched laptops and I cant for the life of me think whats wrong, all the packages are the same versions as before and same version of node.
Any help would be greatly appreciated :)
Thanks!