-
Notifications
You must be signed in to change notification settings - Fork 347
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
DeserializeError
when using lambda_http
with sam local start-api
#797
Comments
As the message says, SAM is sending something that doesn't match the structs that we've defined for those services. In this case If you set the environment |
Thanks for the quick reply, @calavera! Somehow I was not able to get the full event by enabling Then I realised that tracing_subscriber::fmt().with_max_lever(tracing::Level::INFO) // ... Changing this to: tracing_subscriber::fmt()
.with_max_level(
env::var("RUST_LOG")
.unwrap_or("info".to_string())
.parse()
.unwrap_or(tracing::Level::INFO),
) Did the trick, but maybe this could be a separate issue/PR to cargo lambda :) (happy to hear your thoughts on that). Anyway, this is the JSON produced by SAM: {
"body": null,
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Host": "127.0.0.1:3000",
"Sec-Ch-Ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": "\"macOS\"",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"X-Forwarded-Port": "3000",
"X-Forwarded-Proto": "http"
},
"httpMethod": "GET",
"isBase64Encoded": false,
"multiValueHeaders": {
"Accept": [
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"
],
"Accept-Encoding": [
"gzip, deflate, br"
],
"Accept-Language": [
"en-GB,en-US;q=0.9,en;q=0.8"
],
"Cache-Control": [
"max-age=0"
],
"Connection": [
"keep-alive"
],
"Host": [
"127.0.0.1:3000"
],
"Sec-Ch-Ua": [
"\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""
],
"Sec-Ch-Ua-Mobile": [
"?0"
],
"Sec-Ch-Ua-Platform": [
"\"macOS\""
],
"Sec-Fetch-Dest": [
"document"
],
"Sec-Fetch-Mode": [
"navigate"
],
"Sec-Fetch-Site": [
"none"
],
"Sec-Fetch-User": [
"?1"
],
"Upgrade-Insecure-Requests": [
"1"
],
"User-Agent": [
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
],
"X-Forwarded-Port": [
"3000"
],
"X-Forwarded-Proto": [
"http"
]
},
"multiValueQueryStringParameters": null,
"path": "/dump",
"pathParameters": null,
"queryStringParameters": null,
"requestContext": {
"accountId": "123456789012",
"apiId": "1234567890",
"domainName": "127.0.0.1:3000",
"extendedRequestId": null,
"httpMethod": "GET",
"identity": {
"accountId": null,
"apiKey": null,
"caller": null,
"cognitoAuthenticationProvider": null,
"cognitoAuthenticationType": null,
"cognitoIdentityPoolId": null,
"sourceIp": "127.0.0.1",
"user": null,
"userAgent": "Custom User Agent String",
"userArn": null
},
"path": "/dump",
"protocol": "HTTP/1.1",
"requestId": "ea86b9eb-c688-4bbb-8309-a1671442bea9",
"requestTime": "28/Jan/2024:11:05:46 +0000",
"requestTimeEpoch": 1706439946,
"resourceId": "123456",
"resourcePath": "/dump",
"stage": "Prod"
},
"resource": "/dump",
"stageVariables": null,
"version": "1.0"
} At this point, I am still unsure which field is causing the deserialization issue... |
So I did more investigation to try to wrap my head around the issue... As a result, I opened #798, which might be useful and help with having more coverage in the future. Here are my current findings:
Any pointer on how I might be able to investigate this further? |
@lmammino I could reproduce this issue. And when I updated |
I just realised yesterday evening that i was running on lambda_http = "0.8.3"
lambda_runtime = "0.8.3" By updating to |
Also proposed this change so whoever is using |
Thanks for the PR! I'm closing this issue as resolved 🎊 |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Hello! 👋🏽
As usual, thanks for all the excellent work that you are doing to enable devs to ship Lambdas written in Rust.
I recently bumped into the following issue when running
sam local start-api
and then I made a call to the local gateway:These are the versions I am using:
Step-by-step reproduction guide
Follow below the steps to reproduce the issue
1. Start a new project with
cargo lambda
cargo lambda new test-api cd test-api
2. Update handler
Mostly to respond with a JSON body (shouldn't be strictly required)
3. Add a SAM template
4. Start sam local
sam local start-api
Now you can open your browser, for instance pointing it to http://127.0.0.1:3000/test?name=luciano, and you should see the error mentioned above in the
sam local start-api
processThe text was updated successfully, but these errors were encountered: