0

I'm using AWS lambda (Java Runtime) to process some files when there urls are inserted in DynamoDB via another API.

When the lamda dies due to timeout. The lambda is triggered back with the same event and the same process starts again. The process dies again due to timeout and the process starts again.

How can I stop the trigger when timeout occurs ?

The Logs are as follows:

10:53:25 START RequestId: 494ec72d-45bb-409f-bdd4-7653033eefda Version: $LATEST

10:53:25
Received event: com.amazonaws.services.lambda.runtime.events.DynamodbEvent@1e4a7dd4

10:53:25
Got an INSERT EVENT

10:53:25
KEY IS 3c39f7ea-76cf-484f-8a11-39bc2d7c1fd8/aws_dummy.pdf


10:55:25
END RequestId: 494ec72d-45bb-409f-bdd4-7653033eefda

10:55:25
REPORT RequestId: 494ec72d-45bb-409f-bdd4-7653033eefda  Duration: 120035.00 ms  Billed Duration: 120000 ms  Memory Size: 512 MB Max Memory Used: 362 MB Init Duration: 2179.60 ms

10:55:25
2019-09-21T10:55:25.761Z 494ec72d-45bb-409f-bdd4-7653033eefda Task timed out after 120.03 seconds

10:55:28
START RequestId: 494ec72d-45bb-409f-bdd4-7653033eefda Version: $LATEST

10:55:28
Received event: com.amazonaws.services.lambda.runtime.events.DynamodbEvent@1e4a7dd4


10:55:28
Got an INSERT EVENT

10:55:28
KEY IS 3c39f7ea-76cf-484f-8a11-39bc2d7c1fd8/aws_dummy.pdf
public Integer handleRequest(DynamodbEvent event, Context context) {
        for (DynamodbStreamRecord record : event.getRecords()) {
            if (record.getEventName().equals("INSERT")) {
                // DO SOME WORK
                   }
      } 
     return (SOME_INTEGER)
}
Fakabbir Amin
  • 989
  • 7
  • 16
  • Why don't you use step function? Convert your code into steps and sequence them. This should solve your problem of timeout. Here is the help link https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-creating-lambda-state-machine.html – Anup Tilak Sep 21 '19 at 17:13

2 Answers2

2

I would think DynamoDBStream -> Lambda (new Lambda) -> SNS -> SQS -> your lambda now. And having Dead Letter Queue for capture failure one.

Couple reasons for my proposal thoughts 1. The pattern SNS -> SQS is a best practice to send an event and later for extends the feature of communication 2. Having DLQ to handle your failture and you have a control how to process the failed one.

Thanks,

Nghia Do
  • 2,588
  • 2
  • 17
  • 31
1

If i understood your requirement properly then you want your app always actuve on lambda and avoid cold start.

I would suggest if your requirement to keep your app up 24 hrs go with EC2 or ELb as your aws lambda cost same and you no need any hacks.

Now come to your question bow to do that .

Configure CloudWatch.

  • From there, go to Events and click Create rule. Set the event type to Schedule, and we’ll run this event every 1 minute.

  • Select the Lambda function you want to target from the Targets list and Save. you’ll then need to create a name and description.

Now pinging Lambda function every 1 or 5 or 10 or 15 minute as per your need.

vaquar khan
  • 10,864
  • 5
  • 72
  • 96