Reputation: 1065
I'm new to AWS and working on SQS to trigger a lambda function. The order of the function is, Lambda A and pass queue to SQS, then SQS trigger Lambda B.
When I run Lambda A, I see Lambda B is triggered as I expected. However, when I run Lambda A within 5 minutes after the last run of Lambda A, Lambda B is not triggered. I'm wondering if there is a default time set of "5 minutes" to use SQS triggering Lambda function. If so, how can I change to "0 minute"?
Does anybody have the similar issue before? Thanks,
// Lambda A
// sends multiple messages to an Amazon SQS queue
module.exports.handler = async (event, context, callback) => {
try {
// sendQueue function is imported in the head of the file
await sendQueue({ queueMessage }, QUEUE_URL)
} catch (e) {
console.error(e)
}
return {
statusCode: 200,
body: JSON.stringify(
{
message: 'Lambda A is done',
input: event,
},
null,
2
),
}
}
// Lambda B
// After SQS receives queues from Lambda A, SQS triggers to invoke Lambda B
module.exports.handler = async (event, context, callback) => {
// here calling Athena query with "await"
return `Successfully processed a message.`;
}
In Lambda B, it gets a message content everytime the function receives a message from SQS like below.
[
{
messageId: 'b4146e42-a542-4e0e-bff9-ba7f96xxxxxx',
receiptHandle: 'xxxxxxxxxxxxxxx',
body: '{"queueMessage": "queueMessage sample text"}',
attributes: {
ApproximateReceiveCount: '1',
SentTimestamp: '1643094105466',
SequenceNumber: '18867376164708847616',
MessageGroupId: '123',
SenderId: 'xxxxxxxx:lambda-function-name',
MessageDeduplicationId: 'xxxxxx',
ApproximateFirstReceiveTimestamp: '1643094105466'
},
messageAttributes: { ReceiveMessageWaitTimeSeconds: [Object] },
md5OfMessageAttributes: 'aaaaaaaa',
md5OfBody: 'bbbbbbb',
eventSource: 'aws:sqs',
eventSourceARN: 'arn:aws:xxx.fifo',
awsRegion: 'ap-northeast-1'
}
]
Upvotes: 2
Views: 2421
Reputation: 1065
After going over AWS documentation, I found the line below
If a message with a particular message deduplication ID is sent successfully, any messages sent with the same message deduplication ID are accepted successfully but aren't delivered during the 5-minute deduplication interval.
Basically, using FIFO queue of SQS, the messages sent during 5 minutes won't be delivered to avoid sending duplicate messages.
Upvotes: 4
Reputation: 170
Just ensure that you have not set the below setting in SQS. This setting could delay your Lambda function to running after x time.
Upvotes: 1