Closed handlerbot closed 9 months ago
Python3.8 and Python3.9 runtimes have this issue. Python3.7 is not affected. I'll forward your feedback to Lambda service team.
Boo for that, but good to know, and thank you for the quick response and sending the feedback in!
I have updated the issue title to help others who come in and look, please let me know if you want it changed to something else, or feel free to change it yourself if you have the permissions.
really? come on! @bnusunny can you please add it very clearly to the documentation.
Yes. I added a note in the README. The Lambda team is aware of this issue and has a plan to improve this.
@bnusunny and what about new python 3.10? there support added for it?
Not yet. I have one workaround if you are building an API: use Lambda Web Adapter to run your Python API on Lambda. It receives SIGTERM with that tool. Here are examples for running Flask and FastAPI with LWA.
aws-lambda-python-runtime-interface-client#105 has an update with details which may be relevant here.
Great!
Good news! This is fixed in Python 3.12 runtime.
https://aws.amazon.com/blogs/compute/python-3-12-runtime-now-available-in-aws-lambda/
Thanks for the update -- VERY glad to see progress here!
Is there any plan to backport the fix to prior Python versions?
This remains an issue for anyone using 3.8 <= x <= 3.11, which is going to be the vast majority of organizations, as 3.12 isn't even 3 months into GA
Please make a note of this issue on the documentation page. I lost many hours trying to get the examples here to work, before finding this (closed) GitHub issue. I'd say this warrants a large warning message on top of the python readme, considering that the examples in this repo will not currently work for many users.
I made a PR with the documentation change: https://github.com/aws-samples/graceful-shutdown-with-aws-lambda/pull/9
Additional info:
@jodylent
At the moment, the change in 3.12 will not be back-ported to 3.8 to 3.11. People need to use Python 3.12 to get this feature.
Python atexit
module does not trigger on SIGTERM. But you can leverage a signal handler to trigger them. Here is an example.
def sigterm_handler(signum, frame):
print("Received SIGTERM signal")
atexit._run_exitfuncs()
# Register the signal handler for SIGTERM
signal.signal(signal.SIGTERM, sigterm_handler)
At the moment, the change in 3.12 will not be back-ported to 3.8 to 3.11
... [one] can leverage signal handler to trigger
atexit
.
Thank you for the updates -- I'll advertise them internally.
Hi! I implemented this pattern as described in a Lambda function using the Python 3.9 runtime on the ARM architecture in
us-west-2
, and while I'm getting theEXTENSION Name: cloudwatch_lambda_agent State: Ready Events: [SHUTDOWN,INVOKE]
logs, my shutdown handler is never being run.Any suggestions for debugging I can do? Does anyone have a live version of this working for Python (any version, any architecture, any region) that I could try reproducing by matching the successfully working characteristics?
Thanks for any help anyone can provide!