0

I have a lambda function that generates thumbnails on S3 Put event. It works fine. But I want to handle the case when it accidentally takes longer than reserved time(3 sec).

It's because I'm fetching the lambda generated thumbnail by suffixing '-small.jpg' or '-medium.jpg'. If the timeout happens and the thumbnails are not generated, I must have an alternative image in my bucket.

3
  • 1
    Increase the function's timeout and/or configured RAM size. If your processing can potentially take more than the Lambda maximum (15 minutes) then you'll need some more complex solution. Also, rather than trigger on s3:ObjectCreated:Put, you should probably trigger on s3:ObjectCreated:*. Commented Sep 22, 2022 at 14:02
  • @jarmod Can you explain why you recommend s3:ObjectCreated:*? Commented Sep 22, 2022 at 14:08
  • Because objects can be uploaded to S3 via mechanisms other than PUT, for example POST and multipart upload. If you just want to trigger on an object being uploaded, regardless of how it was uploaded, then use s3:ObjectCreated:*. Commented Sep 22, 2022 at 14:17

2 Answers 2

1

if you want to increase function timeout you can edit in the general setting of your function. steps and screenshot below will explain how to do it.

  1. Click on the lambda function hyperlink and click on General Configuration. Screenshot 1

  2. click on edit [top right pane], and increase the function timeout.

2: Screenshot 2

Sign up to request clarification or add additional context in comments.

4 Comments

thanks Praveen, but my question was on handling timeouts. To elaborate, maybe trigger another lambda function on "timeout event"? Or any method that takes a callback that runs on timeout?
module.exports.handler = async (event) => { console.log('Received event:', JSON.stringify(event, null, 2)); try { // Function Logic } catch (err) { console.log('[Handler] - Main function: ', err); // Send the error to Third-party monitoring services } };
You can write logic to your function to do like step function or any function to trigger if retry attempts crossed.
module.exports.handler = async (event) => { console.log('Received event:', JSON.stringify(event, null, 2)); try { // Function Logic } catch (err) { console.log('[Handler] - Main function: ', err); // Send the error to Third-party monitoring services } };
0

I suspect that creating thumbnails will not take more than 15 minutes at maximum Lambda RAM (and correspondingly max CPU) but if you need to handle that possibility then configure your Lambda function with a DLQ and trigger subsequent processing of failed Lambda functions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.