Skip to content

Does Lambda support CancellationToken? #1835

Answered by UnholyRanger
petro2050 asked this question in Q&A
Discussion options

You must be logged in to vote

If you need a cancellation token to pass around, you'll need to implement a CancellationSource in the handler method which will be based on the LambdaContext.RemainingTime. Once that time runs out, AWS will kill the lambda, so you need to subtract enough time to gracefully cancel. They have an example here.
I've implemented an async job as well following the onion architecture (service-provider-repo) and the jobs could run <1 second or upwards of the entire time. I use a cancellation source that subtracts 2 minutes from the remaining time just to be safe and will adjust as needed.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ashishdhingra
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants