AWS Lambda Function Timing Out When Invoked from EventBridge with Large Payload
I'm maintaining legacy code that After trying multiple solutions online, I still can't figure this out... I'm experiencing a timeout scenario with my AWS Lambda function when it is triggered by an EventBridge rule. The Lambda function works fine when tested directly with smaller payloads, but it fails to complete when the payload exceeds 6 MB, resulting in the following behavior: `Task timed out after 6.00 seconds`. The Lambda function is configured with a timeout of 10 seconds, and I'm using Node.js 14.x as the runtime. I've noticed that the payload size from EventBridge is often larger than expected because I'm sending multiple records at once. Here's a simplified version of my Lambda function: ```javascript exports.handler = async (event) => { console.log('Received event:', JSON.stringify(event, null, 2)); // Simulate processing the event for (const record of event.Records) { await processRecord(record); } }; const processRecord = async (record) => { // Simulated processing delay await new Promise(resolve => setTimeout(resolve, 5000)); }; ``` In my EventBridge rule, I'm sending a batch of records, which can vary in size significantly. I've tried increasing the Lambda timeout to 30 seconds, but it still times out when handling larger payloads. I also checked the CloudWatch logs, and while they show the invocation attempt, they don't provide more insight into why it times out. Is there a recommended way to handle larger payloads or a better design pattern for processing multiple records in AWS Lambda? Should I consider splitting the payload into smaller chunks before invoking the Lambda function? Any insights would be greatly appreciated! This is part of a larger API I'm building. What are your experiences with this?