René's URL Explorer Experiment


Title: Support for running code after the response has been returned · Issue #113 · aws/aws-lambda-python-runtime-interface-client · GitHub

Open Graph Title: Support for running code after the response has been returned · Issue #113 · aws/aws-lambda-python-runtime-interface-client

X Title: Support for running code after the response has been returned · Issue #113 · aws/aws-lambda-python-runtime-interface-client

Description: While this request might sound similar to the streaming response feature [see https://github.com//issues/100] now available to Node.js Lambda functions (see https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.ht...

Open Graph Description: While this request might sound similar to the streaming response feature [see https://github.com//issues/100] now available to Node.js Lambda functions (see https://docs.aws.amazon.com/lambda/lates...

X Description: While this request might sound similar to the streaming response feature [see https://github.com//issues/100] now available to Node.js Lambda functions (see https://docs.aws.amazon.com/lambda/lates...

Opengraph URL: https://github.com/aws/aws-lambda-python-runtime-interface-client/issues/113

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support for running code after the response has been returned ","articleBody":"While this request might sound similar to the `streaming response` feature [see https://github.com/aws/aws-lambda-python-runtime-interface-client/issues/100] now available to Node.js Lambda functions (see https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html), it is a separate topic.  \r\n\r\nWe have come across two different use cases where we'd like to run some Python code _after_ returning our response to, say, API Gateway.  One use case is running Python's garbage collector \"manually\" instead of automatically.  Rather than have Python decide to run garbage collection in the middle of our processing of an incoming `event`, and cause our users extra latency, we want to collect the garbage after returning the response.  \r\n\r\nThe other use case involves updating DynamoDb with some bookkeeping about the `event` just serviced.  While we can use an external Lambda Extension to do this, it requires moving a non-trivial amount of data to the Extension process, which seems wasteful assuming we could run this DynamoDb update after returning the response.\r\n\r\nAs a proof of concept, I wrote a monkeypatch to explore feasibility.  I wrote it as a class that I can choose to instance or not at the top of my lambda handler.\r\n\r\n```python\r\nclass PostResponseHook:\r\n    def __init__(self):\r\n        import awslambdaric.bootstrap\r\n\r\n        self.original_handle_event_request = awslambdaric.bootstrap.handle_event_request\r\n        awslambdaric.bootstrap.handle_event_request = self.new_handle_event_request\r\n\r\n    def new_handle_event_request(self, *args, **kwargs):\r\n        self.original_handle_event_request(*args, **kwargs)\r\n        self.hook()\r\n\r\n    def hook(self, *args, **kwargs):\r\n        # do something after the response was returned to the caller here\r\n        pass\r\n```\r\n\r\nThe monkeypatch relies on the current structure of `handle_event_request` in [bootstrap.py](https://github.com/aws/aws-lambda-python-runtime-interface-client/blob/main/awslambdaric/bootstrap.py).  The Lambda function is not finished processing the incoming Event in `handle_event_request`, but, rather, continues back to the \"infinite loop\" in [run](https://github.com/aws/aws-lambda-python-runtime-interface-client/blob/2d0c421ec588a05e6efd8773fa1416fe5433bae0/awslambdaric/bootstrap.py#L461C5-L461C8).\r\n\r\n```python\r\n        while True:\r\n            event_request = lambda_runtime_client.wait_next_invocation()\r\n\r\n            _GLOBAL_AWS_REQUEST_ID = event_request.invoke_id\r\n\r\n            update_xray_env_variable(event_request.x_amzn_trace_id)\r\n\r\n            handle_event_request(\r\n                lambda_runtime_client,\r\n                request_handler,\r\n                event_request.invoke_id,\r\n                event_request.event_body,\r\n                event_request.content_type,\r\n                event_request.client_context,\r\n                event_request.cognito_identity,\r\n                event_request.invoked_function_arn,\r\n                event_request.deadline_time_in_ms,\r\n                log_sink,\r\n            )\r\n```\r\n\r\nThe call to `lambda_runtime_client.wait_next_invocation()` in this loop is where the \"long poll\" for the next Lambda Event occurs (and, presumably, is where the Lambda service will freeze or shutdown this Lambda function instance under most circumstances (see https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html for details.)\r\n\r\n=============================================\r\n\r\nGiven that it seems technically feasible to offer this hook, how could we add this as a supported feature instead of relying on monkeypatching?  It seems that we'd need a way to optionally \"register\" our hook method.  Which would mean exposing a callable from somewhere in `awslambdaric`.  Since I don't know of an existing API already exposed to user code by `awslambdaric`, I don't know where this `register_post_response_hook` method belongs.  \r\n\r\nAlternatively, maybe opting in for this feature would be by means of some special Layer that `awslambdaric` would look for, avoiding the need for explicit opt-in registration by the user's handler?  \r\n\r\n=============================================\r\n\r\nBut I'm probably getting ahead of myself here!  The first question is:  would the `awslambdaric` project consider this kind of hook as desirable, given that it can make a really big difference to latency-sensitive customer use-cases? ","author":{"url":"https://github.com/jrobbins-LiveData","@type":"Person","name":"jrobbins-LiveData"},"datePublished":"2023-09-07T11:49:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/113/aws-lambda-python-runtime-interface-client/issues/113"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:927f5f6e-1044-35cd-cc48-3f08906f55b2
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8AB8:157A5D:899449:BAE78A:6A62E6B2
html-safe-noncee875528e6f64e7ef17175faea60b73e676e1a9b9a04975784067ea483697faf6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QUI4OjE1N0E1RDo4OTk0NDk6QkFFNzhBOjZBNjJFNkIyIiwidmlzaXRvcl9pZCI6IjI1MTIwMTM5MjIzODE1MjI2MTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac8e5e9ef06bb565f892c7415bc553270d09a603e09639271a00185ce309f81523
hovercard-subject-tagissue:1885736171
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/aws/aws-lambda-python-runtime-interface-client/113/issue_layout
twitter:imagehttps://opengraph.githubassets.com/db36fcd6d091be74658fee4d431788c4a8c6ae22f2b92940095b1627afba2046/aws/aws-lambda-python-runtime-interface-client/issues/113
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/db36fcd6d091be74658fee4d431788c4a8c6ae22f2b92940095b1627afba2046/aws/aws-lambda-python-runtime-interface-client/issues/113
og:image:altWhile this request might sound similar to the streaming response feature [see https://github.com//issues/100] now available to Node.js Lambda functions (see https://docs.aws.amazon.com/lambda/lates...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejrobbins-LiveData
hostnamegithub.com
expected-hostnamegithub.com
Nonedf33b1b61ee7b9a0af988199bfc3503c9c1acafb1f1d40e1f140ea7c84f890dd
turbo-cache-controlno-preview
go-importgithub.com/aws/aws-lambda-python-runtime-interface-client git https://github.com/aws/aws-lambda-python-runtime-interface-client.git
octolytics-dimension-user_id2232217
octolytics-dimension-user_loginaws
octolytics-dimension-repository_id292411453
octolytics-dimension-repository_nwoaws/aws-lambda-python-runtime-interface-client
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id292411453
octolytics-dimension-repository_network_root_nwoaws/aws-lambda-python-runtime-interface-client
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
released41cd1bdb290013455c0ac430fa755621733f5eb
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/aws/aws-lambda-python-runtime-interface-client/issues/113#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Faws%2Faws-lambda-python-runtime-interface-client%2Fissues%2F113
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Faws%2Faws-lambda-python-runtime-interface-client%2Fissues%2F113
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=aws%2Faws-lambda-python-runtime-interface-client
Reloadhttps://github.com/aws/aws-lambda-python-runtime-interface-client/issues/113
Reloadhttps://github.com/aws/aws-lambda-python-runtime-interface-client/issues/113
Reloadhttps://github.com/aws/aws-lambda-python-runtime-interface-client/issues/113
Please reload this pagehttps://github.com/aws/aws-lambda-python-runtime-interface-client/issues/113
aws https://github.com/aws
aws-lambda-python-runtime-interface-clienthttps://github.com/aws/aws-lambda-python-runtime-interface-client
Notifications https://github.com/login?return_to=%2Faws%2Faws-lambda-python-runtime-interface-client
Fork 83 https://github.com/login?return_to=%2Faws%2Faws-lambda-python-runtime-interface-client
Star 294 https://github.com/login?return_to=%2Faws%2Faws-lambda-python-runtime-interface-client
Code https://github.com/aws/aws-lambda-python-runtime-interface-client
Issues 22 https://github.com/aws/aws-lambda-python-runtime-interface-client/issues
Pull requests 14 https://github.com/aws/aws-lambda-python-runtime-interface-client/pulls
Discussions https://github.com/aws/aws-lambda-python-runtime-interface-client/discussions
Actions https://github.com/aws/aws-lambda-python-runtime-interface-client/actions
Projects https://github.com/aws/aws-lambda-python-runtime-interface-client/projects
Security and quality 0 https://github.com/aws/aws-lambda-python-runtime-interface-client/security
Insights https://github.com/aws/aws-lambda-python-runtime-interface-client/pulse
Code https://github.com/aws/aws-lambda-python-runtime-interface-client
Issues https://github.com/aws/aws-lambda-python-runtime-interface-client/issues
Pull requests https://github.com/aws/aws-lambda-python-runtime-interface-client/pulls
Discussions https://github.com/aws/aws-lambda-python-runtime-interface-client/discussions
Actions https://github.com/aws/aws-lambda-python-runtime-interface-client/actions
Projects https://github.com/aws/aws-lambda-python-runtime-interface-client/projects
Security and quality https://github.com/aws/aws-lambda-python-runtime-interface-client/security
Insights https://github.com/aws/aws-lambda-python-runtime-interface-client/pulse
Support for running code after the response has been returned https://github.com/aws/aws-lambda-python-runtime-interface-client/issues/113#top
enhancementNew feature or requesthttps://github.com/aws/aws-lambda-python-runtime-interface-client/issues?q=state%3Aopen%20label%3A%22enhancement%22
https://github.com/jrobbins-LiveData
jrobbins-LiveDatahttps://github.com/jrobbins-LiveData
on Sep 7, 2023https://github.com/aws/aws-lambda-python-runtime-interface-client/issues/113#issue-1885736171
/issues/100https://github.com/aws/aws-lambda-python-runtime-interface-client/issues/100
https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.htmlhttps://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html
bootstrap.pyhttps://github.com/aws/aws-lambda-python-runtime-interface-client/blob/main/awslambdaric/bootstrap.py
runhttps://github.com/aws/aws-lambda-python-runtime-interface-client/blob/2d0c421ec588a05e6efd8773fa1416fe5433bae0/awslambdaric/bootstrap.py#L461C5-L461C8
https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.htmlhttps://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html
enhancementNew feature or requesthttps://github.com/aws/aws-lambda-python-runtime-interface-client/issues?q=state%3Aopen%20label%3A%22enhancement%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.