1 réponse
- Le plus récent
- Le plus de votes
- La plupart des commentaires
1
Unfortunately, Lambda doesn't provide a CancellationToken
(to my knowledge). It can, however, tell you the amount of time remaining before it gives up, which you can build a CancellationToken
around. For example:
public async Task<Stream> Process(Stream input, ILambdaContext lambdaContext) { var timeout = lambdaContext.RemainingTime.Subtract(TimeSpan.FromSeconds(5d)); using var cts = new CancellationTokenSource(timeout); await my.Work(cts.Token); return Stream.Null; }
When the RemainingTime
has been reached, Lambda will abruptly shut everything down. There is seemingly no nice way to handle that. Since cancellation is mutual, you'll want to pad the timeout with a few seconds to shut down gracefully. I have arbitrarily selected 5 seconds, but your needs might be different.
When you use the Lambda to ASP.NET Core integration, this process is handled for you automatically and you can just add CancellationToken
as a parameter to your action methods as normal.
répondu il y a 2 ans
Contenus pertinents
- demandé il y a 7 mois
- demandé il y a un an
- demandé il y a un an
- AWS OFFICIELA mis à jour il y a 2 ans
- AWS OFFICIELA mis à jour il y a 3 ans
- AWS OFFICIELA mis à jour il y a un an
- AWS OFFICIELA mis à jour il y a 2 ans