I'm trying to invoke a lambda function within the lambda function using Serverless framework. I'm using this code right now and it works fine when deployed to AWS. But it returns some errors locally in serverless-offline.
Code I'm using right now:
const middy = require("@middy/core");
const httpErrorHandler = require("@middy/http-error-handler");
const httpUrlEncodeBodyParser = require("@middy/http-urlencode-body-parser");
const AWS = require("aws-sdk");
const lambda = new AWS.Lambda();
const baseHandler = async (payload) => {
const params = {
FunctionName: `my-api-${process.env.STAGE}-handleProcessA`,
InvocationType: "Event",
LogType: "None",
Payload: JSON.stringify(payload),
};
await lambda.invoke(params).promise();
return standardResponse();
}
const endpoint = middy(baseHandler)
.use(httpUrlEncodeBodyParser())
.use(httpErrorHandler());
module.exports = { endpoint };
When this is triggered, it says that the function is not found:
Function not found: arn:aws:lambda:us-west-2:893853743015:function:my-api-local-handleProcessA
I tried the suggestions from these SO questions as well: https://mcmap.net/q/2030253/-unable-to-invoke-a-lambda-from-another-lambda-using-aws-serverless-offline https://mcmap.net/q/2030254/-quot-unsupported-media-type-quot-using-serverless-offline
Based on the suggestions, I changed this part:
const lambda = new AWS.Lambda({
region: "us-west-2",
endpoint: process.env.IS_OFFLINE
? "http://localhost:6002"
: "https://lambda.us-west-2.amazonaws.com",
});
But then, it gives me Unsupported Media Type
with status 415. Has anyone encountered this before? Any guidance is appreciated.
Thanks.