Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to access Lambda Context in Python #1815

Closed
unexge opened this issue Oct 5, 2022 · 2 comments · Fixed by #1985
Closed

Provide a way to access Lambda Context in Python #1815

unexge opened this issue Oct 5, 2022 · 2 comments · Fixed by #1985
Labels
enhancement New feature or request python-server Python server SDK

Comments

@unexge
Copy link
Contributor

unexge commented Oct 5, 2022

lambda_http crate provides RequestExt trait to allow accessing some additional information. Currently we convert Lambda request to Hyper request in: https://github.com/awslabs/smithy-rs/blob/main/rust-runtime/aws-smithy-http-server/src/routing/lambda_handler.rs#L49-L89 and we lose the information that specific to Lambda. Ideally we should provide a way to access that information.

I'm not sure what is the best way to do that, maybe we can discuss about adding Lambda specific traits to Smithy IDL, or maybe we can provide that information via Request::extensions in Rust and with a app.lambda_context decorator in Python.

@unexge unexge added server Rust server SDK python-server Python server SDK labels Oct 5, 2022
@david-perez
Copy link
Contributor

Most of that information is stored in request extensions already by the Lambda runtime (e.g. RequestContext), which we preserve in that convert_event function since we reconstruct the request with the converted body type using http::Request::from_parts(parts, body).

So to access it as of now, the user just has to model it in their State and AddExtensionLayer will take care of extracting it.

However, I do think that the general problem of threading request-specific state to service handlers (as opposed to global application state), which includes things like Lambda context, peer IP address, request ID, etc. needs to be solved more ergonomically.

@unexge
Copy link
Contributor Author

unexge commented Nov 1, 2022

@david-perez ohh I missed that. I'll convert this issue to be Python specific. Do we have a tracking ticket for the last part or do you want me to create a ticket for that?

@unexge unexge changed the title Provide a way to access Lambda Context Provide a way to access Lambda Context in Python Nov 1, 2022
@unexge unexge removed the server Rust server SDK label Nov 1, 2022
@crisidev crisidev added the enhancement New feature or request label Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python-server Python server SDK
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants