-
Notifications
You must be signed in to change notification settings - Fork 190
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
feat: support for server lambda_http::Request
#1551
Conversation
rust-runtime/aws-smithy-http-server/examples/pokemon_service/Cargo.toml
Outdated
Show resolved
Hide resolved
lambda_http::Body
lambda_http::Body
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Do you mind to fix the conflict so we can merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry it took me so long to take a look at this, I was on holiday.
I believe the last thing that stands in the way is #1364
#1364 is unrelated to this change. What this change does is to allow smithy-rs to take in lambda_http:Request
s as input, by adding a converter from Lambda's body error type into a smithy-rs RequestRejection
. This will get returned when we fail to buffer non-streaming requests as bytes. You might want to update the PR description / commit message to better reflect the intent of this patch.
I could use some help devising a test; the way I've tested this is by changing the pokemon service to use lambda_http::run in this fashion and witnessing that the code compiles:
It'd be nice if we could showcase a working Lambda in the repo as an example project. #1338 includes a nice example you can copy over. You'll also need to copy over the stage stripping part from the request URI path. Do you want to tackle this in a separate PR?
I am unsure what to put under the CHANGELOG for this change; please advise.
A simple message along the lines of "Add support for accepting input lambda_http::Request
s in the server" will do.
Thank you!
I'm currently taking a week off too, I'll get to this on Monday. Thanks! |
f7cec01
to
f4eae79
Compare
👋 Back dusting this off and see if I can finish the last leg
I probably had the wrong thing to paste here; I believe I intended to link to this comment: #1338 (comment) which had a comment about a workaround to #1364. Sorry for the confusion.
I'd like to get this all done in this PR, so I'll update accordingly, Thanks for the feedback! |
lambda_http::Body
lambda_http::Request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Do you want to copy over Eduardo's cargo lambda
config (see rust-runtime/aws-smithy-http-server/examples/{Makefile, README.md}
in his PR). It would run the new Lambda executable example.
Can you also update the CHANGELOG.next.toml
saying that there is now a canonical and easy way to run smithy-rs on Lambda, linking to the example? We have users doing the old request-response mapping + HTTP URI path stage stripping in their applications, and they'll be happy to know they can get rid of them. Call out in the changelog that there are now converters between SdkBody
and lambda_http::Body
.
rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/main.rs
Outdated
Show resolved
Hide resolved
rust-runtime/aws-smithy-http-server/src/routing/into_make_lambda_service.rs
Outdated
Show resolved
Hide resolved
rust-runtime/aws-smithy-http-server/src/routing/into_make_lambda_service.rs
Outdated
Show resolved
Hide resolved
rust-runtime/aws-smithy-http-server/src/routing/into_make_lambda_service.rs
Outdated
Show resolved
Hide resolved
rust-runtime/aws-smithy-http-server/src/routing/into_make_lambda_service.rs
Outdated
Show resolved
Hide resolved
rust-runtime/aws-smithy-http-server/src/routing/into_make_lambda_service.rs
Outdated
Show resolved
Hide resolved
rust-runtime/aws-smithy-http-server/src/routing/into_make_lambda_service.rs
Outdated
Show resolved
Hide resolved
rust-runtime/aws-smithy-http-server/src/routing/into_make_lambda_service.rs
Outdated
Show resolved
Hide resolved
In your Lambdas, how are you handling usage of the Our users currently have to retrieve it out of the |
New information
I had to do some research yesterday since stage stripping wasn't giving me the expected result. It turns out that as implemented in #1338 we were not stripping anything.
The routing worked at a specific version (sha: eduardomourar@e05b302) because of how the server initializes RequestSpec regexes. Example:
It's subtle but it lacks the start of line assert The new regexes look like this:
After stage stripping it will still not match the versioned path that I have I'm not sure what to do about stripping Edit @david-perez thanks for the review, will work through it today. How are other users dealing with having versioning in their path? Are they adding the version to the path like so?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll need to figure out how to make this work without adding an unconditional lambda dependency to aws-smithy-http
rust-runtime/aws-smithy-http-server/src/routing/into_make_lambda_service.rs
Outdated
Show resolved
Hide resolved
rust-runtime/aws-smithy-http-server/src/routing/into_make_lambda_service.rs
Outdated
Show resolved
Hide resolved
cccfba5
to
43606c7
Compare
I've asked a team member about this; I don't think we do anything with the Lambda context yet. I wasn't involved with our X-Ray integration, but I know we have one, and it works. Maybe this is related, for things like extensions on Request, we've made a RequestExt trait like this:
And |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm from my side thanks!!
Is the version an API Gateway stage? If so, they are stripping it using a similar function than |
Oh right, no, we don't have those in our operation handlers; sorry to mislead, they are only available in middlewares (layers/services) |
@david-perez I made a new set of changes (and rebased) to get the two jobs that were failing to pass |
this is similar to how smithy-typescript deals with this https://github.com/awslabs/smithy-typescript/tree/main/smithy-typescript-ssdk-libs/server-apigateway using raw path here: https://github.com/awslabs/smithy-typescript/blob/ac8fb3f406807bfd14a8f7be8d938377bde36189/smithy-typescript-ssdk-libs/server-apigateway/src/lambda.ts#L51-L59
This refactor is to address multiple pull request review comments 1. Removes the hard dependency between lambda_http and aws-smithy-http 2. Replaces the false MakeService with a Service handler instead, this is terminology that lambda_http::run already uses and should make it explicit to user that a handler like this is needed to convert lambda events to hyper requests 3. Updates the pokemon service example
Co-authored-by: david-perez <[email protected]>
rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lambda.rs
Outdated
Show resolved
Hide resolved
@hugobast Thanks for your contribution.
We will try to address this, perhaps via #1125, so that |
Motivation and Context
This PR replaces: #1338
Adds support for accepting
lambda_http::Request
.Testing
Pokemon Service is updated with a lambda_http run example.
Checklist
CHANGELOG.next.toml
if I made changes to the smithy-rs codegen or runtime cratesCHANGELOG.next.toml
if I made changes to the AWS SDK, generated SDK code, or SDK runtime cratesBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.