0

I have a lambda which does multiple things in parallel (I call async functions and just wait for their Promise.all to be fulfilled before moving on).

The problem: as soon as one of these tasks fails and the async function throws, I want to be able to terminate the lambda and interrupt everything. Something like calling exit(-1). Is there any way to do this?

I don't want to report a failure then have cloudformation do a ROLLBACK (therefore calling my lambda with the event Delete), start deleting/rollbacking stuff and maybe the other async functions were still doing their Create event therefore making a terrible mess. I looked at the CloudWatch logs and it seems that this mess is a totally plausible scenario.

Mark B
  • 183,023
  • 24
  • 297
  • 295
Dean
  • 6,610
  • 6
  • 40
  • 90

1 Answers1

0

Cause you mentioned Promise.all, I assume you have a JavaScript lambda function.

You cannot kill or terminate a lambda function. The engine used (in this case JavaScript), needs to finish all of its executions. You basically need to solve this on the code level and as I understand you want to cancel all other async functions when one throws an error.

You can check answers here or here to better understand what you can do to cancel other promises when one in Promise.all fails. In short, you need to use third-party libraries and wrap some of the code you do not want to continue executing into additional functions chained after the code which can fail.

You also need to figure out what you want to do with non-blocked IO operations (e.g. canceling database transactions) and this depends on the specific operations you execute in your code.

To further alleviate the mess you can check this answer and set lambda function concurrency limit to 0 or create separate lambda functions for each of your async operations and orchestrate them with AWS Step Function.

sorjef
  • 554
  • 5
  • 15