path and query parameters for gateway
Closed this issue · 7 comments
Is there any way to access the pathParameters and queryParameters attributes from the lambda events for a gateway request?
There isn't currently, but I'm generally not opposed to adding support for it. This could be done through the extensions
field on http::Request
.
Would you be interested in contributing this feature? I can provide more detailed instructions if that's useful.
@srijs Is there a reason why the gateway support is not using the types from https://github.com/srijs/rust-aws-lambda/blob/master/aws_lambda_events/src/generated/apigw.rs ? Would it be helpful to derive some builders and/or some Into
on those types?
@LegNeato the main reason was wanting to avoid allocations and copies, e.g. by deserializing the headers directly into http::HeaderMap
rather than going via HashMap<String, String>
, as well as smaller things like Cow<str>
instead of String
in cases where the original string was just going to be parsed and ownership wasn't necessary.
I would've loved to just use our autogenerated types, but I wasn't able to figure out how to best approach this. Maybe you have some ideas?
@srijs Nope, was just wanting to learn about the decision to give me ideas on how I can generate some more / different options to make them usable!
@srijs I would be interested in contributing and in more detailed instructions :)
So, this is how I would approach it, but I don't have any strong opinions at this point, so please let me know if you had something different in mind. Also let me know if anything is unclear or needs more thought!
(I'd prefer if these changes could be feature flagged under something like extensions
-- this will also need to be mapped through on the umbrella crate as gateway-extensions
)
Changes to aws_lambda_gateway
:
- Introduce a feature flag
extensions
- Export wrapper structs for path parameters and query parameters (e.g.
PathParams
andQueryParams
) and add some useful getters to those structs - Add the new fields to the request event definition
ApiGatewayProxyRequestDef
inrequest.rs
- Modify the
ApiGatewayProxyRequestDef::try_into_http_request
method to create the parameter structs and insert them into thehttp::Extensions
viahttp::Request::extensions_mut
- Extend the tests in
request.rs
to check for the extensions
Changes to aws_lambda
:
- Add a feature flag
gateway-extensions
that maps through toaws_lambda_gateway/extensions
- Re-export
PathParams
andQueryParams
from thegateway
module
As we're deprecating this project in favour of https://github.com/awslabs/aws-lambda-rust-runtime, I'm going to close this issue.