When I try to run the lambda function from AWS console the code works fine. Since I want to run a specific code only if there is a new dynamo DB record added, I want to run a lambda function from the dymanoDB stream insert event. I tried the following code, it seems the lambda is not invoking.
Permission in serverless.yml
- Effect: "Allow"
Action:
- "lambda:InvokeFunction"
Resource:
- "*"
Code for dynamoDB stream
exports.main = async (event) => {
const records = event.Records.filter((record) => {
if (record.eventName.toUpperCase() === "INSERT") {
const recordType = record.dynamodb.NewImage.type.S;
if (recordType.toUpperCase() === "TRA") {
// here I capture the value for the arguments. They work fine
inkvokeTraLamda(keyword, key, tag);
}
}
});
};
The function where lambda is called
const AWS = require("aws-sdk");
const lambda = new AWS.Lambda({ region: "us-west-1" });
exports.inkvokeTraLamda = async function invoke(
keyword,
key,
tag
) {
const playload = {
keyword,
key,
tag,
};
const LambdaPromise = (params) => lambda.invoke(params).promise();
const resp = await LambdaPromise(params);
console.log(resp);
return resp;
};
I will highly appreciate your guidance.