Disabling auto-retries in AWS Lambda

Guillaume Khayat
Aug 3, 2017 · 1 min read

Microservices are great for some workflows. At Spectre, we use it for periodic high-concurrency compute jobs, processing thousands of media files. In that area, Amazon offers a pretty decent solution with AWS Lambda. However, Lambda has a few quirks that can range from midly annoying to downright frustrating.

One of those is Lambda’s insistance on automatically retrying failed invokations triggered from “asynchronous invocations” (e.g. S3).


Until the Lambda team gives us some kind of environment variable or setting to disable auto retries, here is a bit of code you can use in your Node Lambdas to mitigate this behaviour:

This code actually leverages Lambda’s quirks to make sure retried Lambda are aborted as soon as possible. It works because :

  • Lambda not only reuses containers, it reuses whole Node processes, keeping global variables instanced and reusable. Useful for caching. Not so much for security and deterministic behaviour.
  • Retried lambdas share the same request Id (e.g. 63f33da6–7833–11e7-a7a4–0badbb709c07)

Edit (2019–11–25): AWS has finally announced a new “Maximum Retry Attempts” setting which makes it possible to disable auto-retries (source: https://aws.amazon.com/about-aws/whats-new/2019/11/aws-lambda-supports-max-retry-attempts-event-age-asynchronous-invocations/)

Written by

Freelance Product Manager

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade