Properly finalize resources on Lambda shutdown
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 195
- Forks
- 53
- PR merge metrics
- No merged PRs in 30d
Description
Spinning @bpholt's comment out of https://github.com/typelevel/feral/issues/134#issuecomment-1003730364.
Currently, we don't run the finalizer for the Resource acquired at the Lambda's startup, which is probably okay in many instances but not ideal. Knowing when to run this finalizer is difficult without some notification/callback from the Lambda environment, and also being explicitly granted some time/backpressure to complete such finalization.
There does seem to be a Lambda Extensions API that supports a shutdown hook, but it's not obvious to me how that would help us inside the actual Lambda.
Shutdown: This phase is triggered if the Lambda function does not receive any invocations for a period of time. In the Shutdown phase, Lambda shuts down the runtime, alerts the extensions to let them stop cleanly, and then removes the environment. Lambda sends a Shutdown event to each extension, which tells the extension that the environment is about to be shut down.
https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html
I also recall someone mentioning that running these finalizers can be time-consuming (i.e. expensive) and doesn't make sense in many cases. So, something to chew on.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or entry points are named. Start by tracing where the Lambda-startup Resource is acquired and reviewing the AWS Lambda Extensions shutdown API. Done would require a defined shutdown signal and a reliable way to complete the Resource finalizer within the available shutdown time.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, scala
- Domain
- backend, cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100