GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Wrong `queryStringParameters` after serializing `AlbTargetGroupRequest`. · Issue #954 · aws/aws-lambda-rust-runtime

Wrong queryStringParameters after serializing AlbTargetGroupRequest. #954

New issue
Copy link
New issue
Copy link
Closed
Closed
Wrong queryStringParameters after serializing AlbTargetGroupRequest.#954
Copy link

Description

@DiscreteTom
DiscreteTom
opened on Jan 3, 2025
Issue body actions

Currently 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"].

Activity

  1. DiscreteTom
    added a commit that references this issue on Jan 3, 2025

    fix: serialize `AlbTargetGroupRequest::query_string_parameters` value…

    This issue will close once commit e29dc51 is merged into the 'main' branch.
    e29dc51
  2. bnusunny commented on Jan 3, 2025

    @bnusunny
    bnusunny
    on Jan 3, 2025
    Collaborator
    More actions

    This is actually the correct behavior. You can verify this by using a real alb to trigger a Lambda function.

  3. DiscreteTom commented on Jan 3, 2025

    @DiscreteTom
    DiscreteTom
    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.

  4. DiscreteTom
    added a commit that references this issue on Jan 8, 2025

    fix: serialize AlbTargetGroupRequest::query_string_parameters with th…

    f7aa516
  5. bnusunny commented on Aug 25, 2025

    @bnusunny
    bnusunny
    on Aug 25, 2025
    Collaborator
    More actions

    @DiscreteTom Sorry, I completely missed this issue. You're actually right.

  6. jlizen
    closed this as completedin b627d76on Aug 26, 2025
  7. github-actions commented on Aug 26, 2025

    @github-actions
    github-actionsBot
    on Aug 26, 2025 – with GitHub Actions
    More actions

    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.

  8. jlizen
    added a commit that references this issue on Aug 26, 2025

    fix: serialize `AlbTargetGroupRequest::query_string_parameters` value…

    This issue will close once commit b627d76 is merged into the 'main' branch.
    b627d76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.