2

I am developing a lambda function that migrates logs from an SFTP server to an S3 bucket.

Due to the size of the logs, the function sometimes is timing out - even though I have set the maximum timeout of 15 minutes.

try:
   logger.info(f'Migrating {log_name}... ')
   transfer_to_s3(log_name, sftp)
   logger.info(f'{log_name} was migrated succesfully ')

If transfer_to_s3() fails due to timeoutlogger.info(f'{log_name} was migrated succesfully') line won't be executed.

I want to ensure that in this scenario, I will somehow know that a log was not migrated due to timeout.

Is there a way to force lambda to perform an action, before exiting, in the case of a timeout?

4
  • "force lambda do something, before timing out?" what does it mean? You can program any logic you want. Commented Oct 25, 2021 at 9:54
  • @Dimitris you can increase the lambda function timeout in Configuration --> General Setting Commented Oct 25, 2021 at 9:59
  • @jebasuthan My question was not phrased correctly. Will edit it. I have already set lambda timeout to 15 minutes which is the maximum allowed. Commented Oct 25, 2021 at 10:32
  • @Marcin Rephrased the question Commented Oct 25, 2021 at 10:36

1 Answer 1

1

Probably a better way would be to use SQS for that:

Logo info ---> SQS queue ---> Lambda function

If lambda successful moves the files, it removes the log info from SQS queue. If it fails, the log info persists in the SQS queue (or goes to DLQ for special handling), so the next lambda invocation can handle it.

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

2 Comments

Just to understand, do you recommend something like: SFTP Server ---> Lambda Function ---> SQS queue ---> Lambda function ? I do not quite get it to be honest
@Dimitris it's not specified in your question how your server works. But if cannot interact with sqs directly, then you can add extra lambda as you described.

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.