aws-samples / graceful-shutdown-with-aws-lambda

MIT No Attribution
75 stars 13 forks source link

Feature: A dummy Rust Lambda extension #1

Open heitorlessa opened 2 years ago

heitorlessa commented 2 years ago

Firstly, thank you for creating this repository. It's a great finding to know any External Lambda Extension gives customers the ability to handle SIGTERM signal.

It'd be great to have a dummy extension instead of Lambda Insights, since the latter can incur charges.

nmoutschen commented 2 years ago

Should be pretty straightforward with the new lambda_extension. We could have a simple no-op service there.

bnusunny commented 2 years ago

Is it available as a cargo crate?

nmoutschen commented 2 years ago

Not yet, but you can use it from git at the moment :)

lambda-extension = { git = "https://github.com/awslabs/aws-lambda-rust-runtime", branch = "master" }
heitorlessa commented 2 years ago

Apparently you can just call /register RAPID API as an “internal extension” and you also get the SIGTERM Benefit without needing s Layer and such

On Thu, 27 Jan 2022 at 16:58, Nicolas Moutschen @.***> wrote:

Not yet, but you can use it from git at the moment :)

lambda-extension = { git = "https://github.com/awslabs/aws-lambda-rust-runtime", branch = "master" }

— Reply to this email directly, view it on GitHub https://github.com/aws-samples/graceful-shutdown-with-aws-lambda/issues/1#issuecomment-1023365342, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZPQBBAPHKQKO4MDYX34UDUYFTQPANCNFSM5M56QK6A . You are receiving this because you authored the thread.Message ID: @.*** com>

ldragone commented 1 year ago

@heitorlessa could you explain what you mean by "call/register RAPID API as an internal extension"? I haven't found any other examples on the internet that explain how to read SIGTERM signals without registering an extension.

Thanks in advance!

bnusunny commented 1 year ago

@luigidragone96 an internal extension is a thread in a lambda function that talks to the extension API. We have some examples. I will post it here once I found it.

ldragone commented 1 year ago

Thank you! The examples would be very useful. At the moment I am using the workaround using an AWS managed extension, in particular the new extension for get parameter and secrets from SSM.

bnusunny commented 1 year ago

This is for python. Put the code outside of your handler.

image

ldragone commented 1 year ago

@bnusunny thanks for sharing this example. I tried to do something similar with a lambda in NodeJS but I get the error 403 "Extension registration closed already"

{"errorMessage":"Extension registration closed already","errorType":"Extension.RegistrationClosed"}

NodeJS lambdas don't support internal extensions?

bnusunny commented 1 year ago

Could you share your test code? Extension registration should happen during the init phase (before the handler function is called).

anzemur commented 1 year ago

So we can't use the graceful shutdown if we don't use any external extensions? Is there a way to create a dummy extension in Node.js that would serve only to catch the SIGTERM signal in lambda handler?

bnusunny commented 1 year ago

Both external and internal extensions can enable graceful shutdown.

You can create an internal extension in node.js following the python example I posted above.

anzemur commented 1 year ago

@bnusunny Thank you! Do you have an example of an internal extension written for Node.js, or maybe just a code example with some descriptions of what we should do and why?