我有一个Foo
lambda,它使用Vandium来调用另一个Bar
lambda,如下所示:
'use strict';
const aws = require('aws-sdk');
const vandium = require('vandium');
const parameterValidation = {
body: {
foo: vandium.types.string().required(),
}
};
exports.foo = vandium.api()
.callbackWaitsForEmptyEventLoop(false)
.POST(parameterValidation, (event) => {
console.log('Recieved POST request - invoking bar lambda...');
new aws.Lambda().invoke({
FunctionName: 'bar',
Payload: JSON.stringify(event.body),
}, (error, data) => {
console.log('bar lambda returned to foo lambda...');
if (error) {
throw new Error('bar lambda returned an error');
} else {
return {
data: data.Payload.data,
};
}
});
console.log('foo lambda did not wait for bar lambda to return!');
});
这是Bar
lambda:
'Use strict';
exports.handler = (event, context, callback) => {
callback(null, {
data: "yay",
});
};
当我使用API网关代理Lambda测试事件执行Foo lambda时,它会打印foo lambda did not wait for bar lambda to return!
。如何使foo lambda实际上从bar lambda获取值?