Skip to content

Multiple queryStringParameters ignored in sam local start-api for HTTP APIs #3194

@EpicSquid

Description

@EpicSquid

Description:

I have a simple lambda function which takes multiple query string parameters, however only the last query string parameter is kept.

Steps to reproduce:

I have defined a function as follows:

TestFunction:
    Type: AWS::Serverless::Function 
    Properties:
      CodeUri: rest_api/test/
      Events:
        GetTest:
          Type: HttpApi
          Properties:
            Path: /api/test
            Method: get

Then run the application with sam local start-api --debug

Then sent a query to it using postman as a GET request: http://localhost:3000/api/test?test_ids=1&test_ids=2

Observed result:

The event output for the function is the following

Constructed String representation of Event Version 2.0 to invoke Lambda. Event: 
{
  "version": "2.0",
  "routeKey": "GET /api/test",
  "rawPath": "/api/test",
  "rawQueryString": "test_ids=1&test_ids=2",
  "cookies": [],
  "headers": {
    "Content-Type": "application/json",
    "User-Agent": "PostmanRuntime/7.28.3",
    "Accept": "*/*",
    "Postman-Token": "cb0df40e-920d-4f8d-bbf8-9381f9ee5e45",
    "Host": "localhost:3000",
    "Accept-Encoding": "gzip, deflate, br",
    "Connection": "keep-alive",
    "Content-Length": "21",
    "X-Forwarded-Proto": "http",
    "X-Forwarded-Port": "3000"
  },
  "queryStringParameters": {
    "test_ids": "2"
  },
  "requestContext": {
    "accountId": "123456789012",
    "apiId": "1234567890",
    "http": {
      "method": "GET",
      "path": "/api/test",
      "protocol": "HTTP/1.1",
      "sourceIp": "127.0.0.1",
      "userAgent": "Custom User Agent String"
    },
    "requestId": "46b22e74-8e33-4f90-8f5c-3af887356c8e",
    "routeKey": "GET /api/test",
    "stage": null
  },
  "body": "",
  "pathParameters": {},
  "stageVariables": null,
  "isBase64Encoded": false
}

Critically:

"queryStringParameters": {
    "test_ids": "2"
  },

Expected result:

I expected the following parsing for the queryStringParameters, as per the documentation

"queryStringParameters": {
    "test_ids": "1,2"
  },

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Windows 10
  2. sam --version: 1.29.0
  3. AWS region: ap-southeast-2

Add --debug flag to command you are running

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions