✅ async/await Task in an AWS Lambda
Given the following code
without explicitly doing
await someWorkTasks;
it is possible that the lambda execution will get cut off/finish before that has a change to complete, right?
I'm not insane? I need to explicitly await someWorkTasks;
to ensure everything inside it finished, right?13 Replies
my intuition says "yeah", but I don't really know
let's see....
are you asking because AWS Lambdas can't be
async
?
looking at the docs, I think that's possibly true?
nope, nevermind, there it is
okay, here we go, the docs explicitly state that this is the case
the lambda is subject to teardown as soon as it returns
or as soon as its returned Task
completes
so, if you have something within that's not being await
ed, that can definitely get terminated before it finishesLambda function handler in C# - AWS Lambda
Learn how to define a Lambda function handler for C# functions.
near the bottom of the page
If you create an async Lambda function without implementing the await operator, .NET will issue a compiler warning and you will observe unexpected behavior. For example, some async actions will run while others won't. Or some async actions won't complete before the function invocation completes.are you just curious, or is there some reason why you want to not await something? are you maybe trying to run some background work, where it keeps going after the lambda returns a basic acceptance result?
Yeah you have to await it somewhere
so, inside the block, there's various webservices and records being created in different places, along with logging, as things are happening
starting XYZ....
dbContext insert record
finished XYZ...
starting ABC...
webservice called
finsihed ABC...
and at times, all the data and accompanying log lines are there.
other times, it doesnt.
there's no errors being thrown, because they're handled.
what I am notificing is the timestamps.
in the cases where all the expected stuff isn't there, the overall execution of the log entries is getting to be over 1min.
in the cases where all the expected stuff IS there, the execution duration is much shorter
well, that could certainly be explained by you not awaiting something
this is after a stupid switch from elastic beanstalk over to lambdas.
in EB, these issues were never happening, because the damn process was always "alive"
in lambda, it's finish quickly or it gets killed off
it's an entirely different issue if AWS is killing your stuff prematurely, because it takes too long
essentially stuffed the entire damn api website into a lambda and now all sorts of issues are cropping up. and that's the only thing I can think of, because after repeated tests on my machine, everything works
according to docs, the timeout for a lambda to run is configurable by you, up to 15 minutes
right, but if i'm not awaiting
someWorkTasks
i dont think lambda is aware that there's still some shit taking place in the background, right?
like that's what im left with, after many many tests on my local machineyes, if you're not awaiting something, that would explain it
and could also explain you not seeing the issue locally
awesome. thank you guys for chiming in and confirming my sanity.