Most active commenters

    ←back to thread

    115 points nonfamous | 13 comments | | HN request time: 0.639s | source | bottom
    1. johnduhart ◴[] No.44567380[source]
    Oh wow, a 23-page write up about how the author misunderstood AWS Lambda's execution model [1].

    > It emits an event, then immediately returns a response — meaning it always reports success (201), regardless of whether the downstream email handler succeeds or fails.

    It should be understood that after Lambda returns a response the MicroVM is suspending, interrupting your background HTTP request. There is zero guarantee that the request would succeed.

    1: https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-...

    replies(4): >>44567460 #>>44568625 #>>44568884 #>>44573721 #
    2. kevin_nisbet ◴[] No.44567460[source]
    I don’t know about node but a fun abuse of this is background tasks can still sometimes run on a busy lambda as the same process will unsuspend and resuspend the same process. So you can abuse this sometimes for non essential background tasks and to keep things like caches in process. You just cant rely on this since the runtime instead might just cycle out the suspended lambda.
    replies(3): >>44567489 #>>44569182 #>>44578407 #
    3. johnduhart ◴[] No.44567489[source]
    Absolutely, I do this at $dayjob to update feature flags and refresh config. Your code just needs to understand that such execution is not guaranteed to happened, and in-flight requests may get interrupted and should be retried.
    4. frenchtoast8 ◴[] No.44568625[source]
    It took me a couple reads of the PDF but I think you're right. The author creates an HTTP request Promise, and then immediately returns a response thereby shutting down the Lambda. They have logging which shows the background HTTP request was in the early stages of being sent to the server but the server never receives anything. They also have an error handler that is supposed to catch errors during the HTTP request but it isn't executed either. The reason for both seems quite obvious: it's completely expected that a Lambda being shutdown wouldn't finish making the request and it certainly wouldn't stick around to execute error handling code after the request was cancelled.

    As an aside I find it strange that the author spent all this time writing this document but would not provide the actual code that demonstrates the issue. They say they wrote "minimal plain NodeJS functions" to reproduce it. What would be the reason to not show proof of concept code? Instead they only show code written by an AWS engineer, with multiple caveats that their code is different in subtle ways.

    The author intends for this to be some big exposé of AWS Support dropping the ball but I think it's the opposite. They entertained him through many phone calls and many emails, and after all that work they still offered him a $4000 account credit. For comparison, it's implied that the Lambda usage they were billed for is less than $700 as that figure also includes their monthly AWS Support cost. In other words they offered him a credit for over 5x the financial cost to him for a misunderstanding that was his fault. On the other hand, he sounds like a nightmare customer. He used AWS's offer of a credit as an admission of fault ("If the platform functioned correctly, then why offer credits?") then got angry when AWS reasonably took back the offer.

    5. dsmurrell ◴[] No.44568884[source]
    "This document reflects the outcome of a seven-week independent technical investigation" - :)
    replies(1): >>44569697 #
    6. lbreakjai ◴[] No.44569182[source]
    I wouldn't really call this an abuse. I remember their documentation mentioning it.
    7. Hikikomori ◴[] No.44569697[source]
    Guy seems to be a consultant, so good money invoiced on this "problem".
    8. belter ◴[] No.44573721[source]
    Uhhmm… it seems both you and @frenchtoast8 are misrepresenting the code flow. The author doesn’t return early, the handler is async and explicitly awaits an https.request() Promise. The return only happens after the request resolves or fails. Lambda is terminating mid-await, not post-return.

    That’s the whole point and it’s not the behavior your comments describe.

    replies(2): >>44573944 #>>44574790 #
    9. Scaevolus ◴[] No.44573944[source]
    Page 5: "It emits an event, then immediately returns a response — meaning it always reports success (201), regardless of whether the downstream email handler succeeds or fails."

    This is not the right way to accomplish this. If you want a Lambda function to trigger background processing, you invoke another lambda function before returning. Using Node.js events for background processing doesn't work, since the Lambda runtime shuts down the event loop as quickly as possible.

    replies(1): >>44575264 #
    10. souldeux ◴[] No.44574790[source]
    Respectfully, the documentation makes it clear that the author is incorrect.
    replies(1): >>44593725 #
    11. ◴[] No.44575264{3}[source]
    12. __turbobrew__ ◴[] No.44578407[source]
    TiTiler does exactly that. Geospatial rasters are stored in S3, and the lambda retains a cache in memory of loaded data from S3. So if the same lambda execution is used it can return cached data without hitting S3.
    13. belter ◴[] No.44593725{3}[source]
    The comments here are focusing on the code description by the author, of code he did not post, and the confusing explanations of the author, while ignoring the incorrect but demonstrative test case from AWS.

    If you talk about documentation, and in this thread there have been many mentions of it, without citing specific paragraphs, we could start with this one from here [1]:

    "Using async/await (recommended)"

    "...The async keyword marks a function as asynchronous, and the await keyword pauses the execution of the function until a Promise is resolved..."

    Or

    "Using callbacks"

    "...The function continues to execute until the event loop is empty or the function times out. The response isn't sent to the invoker until all event loop tasks are finished. If the function times out, an error is returned instead. You can configure the runtime to send the response immediately by setting context.callbackWaitsForEmptyEventLoop to false..."

    [1] https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler....

    It actually seems, the most likely that happendd here, were random disconnects from the VPC, that neither the author or AWS support were able to contextualize.