GeezerVison is showing github.com — Wrong `queryStringParameters` after serializing `AlbTargetGroupRequest`. · Issue #954 · aws/aws-lambda-rust-runtime
Wrong queryStringParameters after serializing AlbTargetGroupRequest. #954DescriptionCurrently AlbTargetGroupRequest::query_string_parameters is serialized with the default QueryMap serializer, which will serialize the value as a list instead of a string.
https://github.com/awslabs/aws-lambda-rust-runtime/blob/f69280e9b92e9a7acc92cfa04a860d9b2b83b5c0/lambda-events/src/event/alb/mod.rs#L19-L20
It should be serialized like in APIGW event, using query_map::serde::aws_api_gateway_v1::serialize_query_string_parameters.
https://github.com/awslabs/aws-lambda-rust-runtime/blob/f69280e9b92e9a7acc92cfa04a860d9b2b83b5c0/lambda-events/src/event/apigw/mod.rs#L34-L35
Minimal repro:
#[cfg(test)]
mod tests {
use aws_lambda_events::alb::{AlbTargetGroupRequest, AlbTargetGroupRequestContext, ElbContext};
use axum::http::{request::Builder, Method};
use std::collections::HashMap;
#[test]
fn test() {
let (parts, body) = Builder::new()
.method(Method::GET)
.uri("https://example.com/")
.header("key", "value")
.body("")
.unwrap()
.into_parts();
let query_string_parameters = HashMap::from([("k".to_string(), "v".to_string())]).into();
let json = serde_json::to_string(&AlbTargetGroupRequest {
http_method: parts.method,
headers: parts.headers,
path: "/".to_string().into(),
query_string_parameters,
body: body.to_string().into(),
is_base64_encoded: false,
request_context: AlbTargetGroupRequestContext {
elb: ElbContext { target_group_arn: None },
},
multi_value_headers: Default::default(),
multi_value_query_string_parameters: Default::default(),
})
.unwrap();
println!("{}", json);
}
}
Got output:
{"httpMethod":"GET","path":"/","queryStringParameters":{"k":["v"]},"multiValueQueryStringParameters":{},"headers":{"key":"value"},"multiValueHeaders":{},"requestContext":{"elb":{"targetGroupArn":null}},"isBase64Encoded":false,"body":""}
Expected: the value of "k" in queryStringParameters should be a string "v" instead of a list ["v"]. Activityadded a commit that references this issue on Jan 3, 2025This issue will close once commit e29dc51 is merged into the 'main' branch.e29dc51 bnusunny commented on Jan 3, 2025 This is actually the correct behavior. You can verify this by using a real alb to trigger a Lambda function. DiscreteTom commented on Jan 3, 2025 ContributorAuthor More actions Tested with a real ALB (multi-value-headers disabled) and a nodejs lambda function to print the event using console.log(JSON.stringify(event));. Here are the results:
Case 1:
curl 1234567890.us-east-1.elb.amazonaws.com/lambda?k=v
Output:
{
"requestContext": {
"elb": {
"targetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:1234567890:targetgroup/lambda-print-request/1234567890"
}
},
"httpMethod": "GET",
"path": "/lambda",
"queryStringParameters": {
"k": "v"
},
"headers": {
"accept": "*/*",
"host": "1234567890.us-east-1.elb.amazonaws.com",
"user-agent": "curl/8.9.1",
"x-amzn-trace-id": "Root=1-1234567890-1234567890",
"x-forwarded-for": "1.1.1.1",
"x-forwarded-port": "80",
"x-forwarded-proto": "http"
},
"body": "",
"isBase64Encoded": false
}
Case 2:
curl "1234567890.us-east-1.elb.amazonaws.com/lambda?k=v&k=v2"
Output:
{
"requestContext": {
"elb": {
"targetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:1234567890:targetgroup/lambda-print-request/1234567890"
}
},
"httpMethod": "GET",
"path": "/lambda",
"queryStringParameters": {
"k": "v2"
},
"headers": {
"accept": "*/*",
"host": "1234567890.us-east-1.elb.amazonaws.com",
"user-agent": "curl/8.9.1",
"x-amzn-trace-id": "Root=1-1234567890-1234567890",
"x-forwarded-for": "1.1.1.1",
"x-forwarded-port": "80",
"x-forwarded-proto": "http"
},
"body": "",
"isBase64Encoded": false
}
The behavior follows the documentation:
With the default format, the load balancer uses the last value sent by the client and sends you an event that includes query string parameters using queryStringParameters.
bnusunny commented on Aug 25, 2025 @DiscreteTom Sorry, I completely missed this issue. You're actually right. github-actions commented on Aug 26, 2025 This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one. added a commit that references this issue on Aug 26, 2025This issue will close once commit b627d76 is merged into the 'main' branch.b627d76
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|