8000 Issue with multiple cookies (array) in v2 Lambda proxy integration payload · Issue #12577 · localstack/localstack · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Issue with multiple cookies (array) in v2 Lambda proxy integration payload #12577

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

Closed
1 task done
mountmike opened this issue May 5, 2025 · 6 comments
Closed
1 task done
Assignees
Labels
aws:lambda AWS Lambda status: resolved/fixed Resolved with a fix or an implementation type: bug Bug report

Comments

@mountmike
Copy link
mountmike commented May 5, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

A lambda that returns a response which looks like this (ts type APIGatewayProxyStructuredResultV2)

{
  statusCode: 302,
  headers: {
      Location: authorizationUrl,
  },
  cookies: [
    "cookie1=value1; Path=/; HttpOnly; Secure; SameSite=None",
    "cookie2=value2; Path=/; HttpOnly; Secure; SameSite=None"
  ],
  body: ''
};

only adds one Set-Cookie header with a cookie that contains the joined value of all cookies in the array.

Expected Behavior

In the response, each cookie in the array becomes a set-cookie header as per the AWS docs: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html#http-api-lambda-response-format

This is what occurs when I am deployed on AWS but no when I deploy with localstack

How are you starting LocalStack?

With the localstack script

Steps To Reproduce

How are you starting localstack (e.g., bin/localstack command, arguments, or docker-compose.yml)

`USE_SSL=1 localstack start`

Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)

My issue is from a CDK app running cdklocal deploy but here are some steps to replicate thanks to the robot overlord.

  1. Create the IAM role for Lambda
aws iam create-role \
  --role-name lambda-exec-role \
  --assume-role-policy-document '{
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Principal": { "Service": "lambda.amazonaws.com" },
        "Action": "sts:AssumeRole"
      }
    ]
  }' \
  --endpoint-url https://localhost.localstack.cloud:4566
  1. Create the Lambda function
echo 'exports.handler = async () => ({
  statusCode: 200,
  cookies: [
    "cookie1=value1; Path=/; HttpOnly; Secure; SameSite=None",
    "cookie2=value2; Path=/; HttpOnly; Secure; SameSite=None"
  ],
  body: "Set multiple cookies"
});' > index.js

zip function.zip index.js
aws lambda create-function \
  --function-name set-cookie-test \
  --runtime nodejs18.x \
  --handler index.handler \
  --role arn:aws:iam::000000000000:role/lambda-exec-role \
  --zip-file fileb://function.zip \
  --endpoint-url https://localhost.localstack.cloud:4566
  1. Create an HTTP API Gateway
aws apigatewayv2 create-api \
  --name "SetCookieTestAPI" \
  --protocol-type HTTP \
  --target arn:aws:lambda:us-east-1:000000000000:function:set-cookie-test \
  --endpoint-url https://localhost.localstack.cloud:4566
  1. Export API id for next step export API_ID=your-api-id-here
  2. Add integration and route
aws apigatewayv2 create-integration \
  --api-id $API_ID \
  --integration-type AWS_PROXY \
  --integration-uri arn:aws:lambda:us-east-1:000000000000:function:set-cookie-test \
  --payload-format-version 2.0 \
  --integration-method POST \
  --endpoint-url https://localhost.localstack.cloud:4566
  1. Export the integration id for next step export INTEGRATION_ID=your-integration-id-here
  2. Create the route
aws apigatewayv2 create-route \
  --api-id $API_ID \
  --route-key "GET /test" \
  --target integrations/$INTEGRATION_ID \
  --endpoint-url https://localhost.localstack.cloud:4566
  1. Deploy the API
aws apigatewayv2 create-deployment \
  --api-id $API_ID \
  --endpoint-url https://localhost.localstack.cloud:4566
  1. Test the endpoing
curl -i https://$API_ID.execute-api.localhost.localstack.cloud:4566/test

Environment

- OS: Mac OS 15.4.1
- LocalStack: 
  LocalStack version: 3.5.0
  LocalStack Docker image sha: sha256:55a9ca4d50c31dbab0ea194a99aace23ce77f4806b9e4277b0055f1d3b6009a4
  LocalStack build date: 2025-05-02
  LocalStack build git hash:6acdef4e5

Anything else?

No response

@mountmike mountmike added status: triage needed Requires evaluation by maintainers type: bug Bug report labels May 5, 2025
@localstack-bot
Copy link
Collaborator

Welcome to LocalStack! Thanks for reporting your first issue and our team will be working towards fixing the issue for you or reach out for more background information. We recommend joining our Slack Community for real-time help and drop a message to LocalStack Support if you are a licensed user! If you are willing to contribute towards fixing this issue, please have a look at our contributing guidelines.

@mountmike
Copy link
Author

I see on here: https://docs.localstack.cloud/references/coverage/coverage_apigatewayv2/

There is tests for test_lambda_payload_format[2.0]LocalStack Pro: tests/aws/services/apigatewayv2/test_apigatewayv2_aws_proxy.py::TestHttpApiAwsProxyIntegration::test_lambda_payload_format[2.0]

I was trying to locate this test file to see if there was a test case around multiple cookies but couldn't find this test in the localstack repo?

@Anze1508 Anze1508 added aws:lambda AWS Lambda status: backlog Triaged but not yet being worked on and removed status: triage needed Requires evaluation by maintainers labels May 5, 2025
@bentsku bentsku self-assigned this May 5, 2025
@bentsku bentsku added status: confirmed Bug report was confirmed and removed status: backlog Triaged but not yet being worked on labels May 5, 2025
@bentsku
Copy link
Contributor
bentsku commented May 5, 2025

Hello @mountmike and thanks for your report!

This issue is due to how our Python HTTP request library serializes the response in our tests. We believed AWS API Gateway returned the set-cookie concatenated with commas, but this was a serialization made by the library, which lead us to the wrong implementation.
We're now working with raw HTTP response, and will look into fixing this issue. I'll update you on the progress.

Regarding the test file, this is in our closed source offering (Pro services) which explains why it's not in this repo. Thanks!

@mountmike
Copy link
Author

Hi and thanks @bentsku

Could you clarify what you mean by my Python HTTP request library? Are you saying this might have something to do with a library/dependency in my environment?

@bentsku
Copy link
Contributor
bentsku commented May 6, 2025

Hello @mountmike! I'm really sorry for the misunderstanding, I meant "our" Python requests library, used in our tests.
The fix has been merged yesterday and should now be available in the latest Docker image. Could you try pulling the latest Pro image by running docker pull localstack/localstack-pro:latest and give it a try to see if that fixes your issue? Thanks!

If the issue is still not resolved, please feel free to comment and I'll re-open the issue. Thanks!

@bentsku bentsku added status: response required Waiting for a response from the reporter and removed status: confirmed Bug report was confirmed labels May 6, 2025
@bentsku bentsku closed this as completed May 6, 2025
@bentsku bentsku added status: resolved/fixed Resolved with a fix or an implementation and removed status: response required Waiting for a response from the reporter labels May 6, 2025
@mountmike
Copy link
Author

Wow @bentsku that was quick - fantastic! I've just tested and it's working. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:lambda AWS Lambda status: resolved/fixed Resolved with a fix or an implementation type: bug Bug report
Projects
None yet
Development

No branches or pull requests

4 participants
0