One Lambda is calling another in a synchronous manner, gets some data and continues in processing.
This means, the costs are taken into account for both Lambdas in the call time period.
Is it possible to use AWS Step Functions in this case without breaking the processing into a state machine blocks, which would make the code too complex?
Node.js 8.10 code:
const AWS = require('aws-sdk');
const lambda = new AWS.Lambda({ apiVersion: '2015-03-31' });
exports.handle = async event => {
try {
const packageId = event.pathParameters['id'];
const entry = await packageEntry(packageId);
const tags = await tagsForEntry(entry.id);
return httpResponse(200, { ...entry, tags });
}
catch (err) {
return httpResponse(500, err.message);
}
}
async function tagsForEntry(entryId) {
const response = await lambda.invoke({
FunctionName: process.env.TAGGING_LAMBDA,
InvocationType: 'RequestResponse',
Payload: JSON.stringify({
method: 'GET_TAGS',
payload: { entryId }
})
}).promise();
const payload = response.Payload ? JSON.parse(response.Payload.toString()) : {};
return payload.tags || [];
}
async function packageEntry(packageId) {
// return a package entry from a database
}
function httpResponse(statusCode, data) {
// return a HTTP response object
}