Retry on invoke for AWS Lambda?



I’m seeing something very strange when attempting to invoke a lambda on AWS.

I call sls invoke -f --stage --profile

The invoked lambda runs - and then 30-40 seconds later, runs again, and possibly again.

I can’t see anything in the script that would cause this, and I don’t get the same behaviour if I test the lambda from the web console.

Im not seeing any log info coming back into the console that I exec the sls command from - is there some form of retry going on?




I believe that by default, AWS will retry a failing Lambda 2 times (with exponential backoff)


Thanks Trent -

I re-read the retry documentation : - and I see it says the same thing.

I must have missed the first failure somehow so it looked like the lambda was just being run twice - every time…




First rule of Serverless is Lambda’s must be idempotent.

That said, it does sounds funny. Normally this only happens occasionally.


Agreed - and that’s true in this case too - I only spotted it because it was screwing up my monitoring. A lambda that appeared to be succeeding was still showing as an error!

As it is, the root issue turned out to be an hidden asynchronicity in elasticsearch which highlighted an unhandled exception path in my code. So the first invocation failed, but the second worked.

As Trent (and the documentation) points out - there’s an automatic retry when the lambda is invoked by an event - so whilst it looked like voodoo, it was actually doing the right thing!