-
Notifications
You must be signed in to change notification settings - Fork 361
Failed to build request panic #505
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
Comments
Hey @NathanielCurnick! IIRC, the fact that those JSON requests are malformatted just means that they won't correspond to what Lambda actually receives from API Gateway/ALB, thus it's unlikely that an actual user would face that situation unless you're not invoking the functions from APIGW/ALB/Lambda URLs. |
Thanks for the reply @nmoutschen! Looking at it, I think you're right that some formatting is done by the API Gateway, at least from what I gathered from those old threads. It still irks me slightly that there's a potential crash I can not handle. Maybe an alternative solution is to have the |
Can you share the payload that you're trying to use? What do you exactly mean by "bad request", API Gateway guarantees that the JSON has a consistent format. Testing payloads with missing fields that API Gateway guarantees might not be very useful. |
Btw, if you're testing HTTP requests, the function URL endpoint might be more useful in your case: https://github.com/cargo-lambda/cargo-lambda/#watch---function-urls |
@NathanielCurnick this is an example of the payload that API Gateway sends to Lambda: https://github.com/LegNeato/aws-lambda-events/blob/master/aws_lambda_events/src/generated/fixtures/example-apigw-request.json In that example, your app's payload goes into the |
Hi @calavera, thanks for your reply! I'm using the The sample data I am using is a POST request JSON like this If I make this request to the Lambdas deployed on AWS it is successful, but locally this fails since it is missing the extra wrapping from the API Gateway. I would rather the way I interact with and test both local running Lambda functions and Lambda functions actually on AWS remains consistent. Right now it seems the only option is for me to manually reproduce this request wrapping, which I would rather avoid because I want to test exactly how a client would interact with the Lambda function |
Right, this doesn't happen because A way that we could fix this would be by adding a flag to
Contributions to make that happen are very welcome 😉 |
That sounds like a perfect solution. Is there any documentation on how the API Gateway specifically wraps requests? I can make a fork for this soon |
Actually, now that I look more closely at you example, I don't think that's going to work because that's not really how ApiGW translates payloads. ApiGW is going to take your http request and translate it into a Lambda event that looks like the one in the example above. It's not a simple wrapper. There are attributes in the requests mapped to specific fields in the payload. Fields like The three options I see are these:
I would personally focus on 1, or 2, because they will allow you to test what you need to test without waiting for major development changes. |
No 2 has proven to be the winner for my needs! Thanks for all your help @calavera @nmoutschen ! |
Uh oh!
There was an error while loading. Please reload this page.
Hi there,
Working with the local testing environment for lambdas with
cargo lambda watch
andcargo lambda invoke <lambda> --data-file test_payload.json
panics the main Tokio thread withfailed to build request
from here. Looking at older issues #368 #423 #445 the answers seem to be revolving around the test jsons are malformatted and need extra fields. However, I specifically want to test the behavior of the lambda when it does receive a bad request. I'd there to be a way to get an error from the conversion to an HTTP request, so I can explicitly handle this and return an error to the user?The text was updated successfully, but these errors were encountered: