Skip to content
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

ELB Support / Fix: APIGW v2 cookies response #155

Merged
merged 9 commits into from
Feb 13, 2021

Conversation

araki-yzrh
Copy link
Contributor

Issue: #149

Hi.
im added ELB support code and tests.
and support APIGW v2 cookies response

see also: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html

ELB has two modes.

  • single value header and query mode (default)
  • multi value header and query mode

Single Value Mode

request event

{
    "requestContext": {
        "elb": {
            "targetGroupArn": "arn:aws:elasticloadbalancing:region:123456789012:targetgroup/my-target-group/6d0ecf831eec9f09"
        }
    },
    "httpMethod": "GET",
    "path": "/",
    "queryStringParameters": { "myKey": "val1" },
    "headers": {
        "accept": "text/html,application/xhtml+xml",
        "accept-language": "en-US,en;q=0.8",
        "content-type": "text/plain",
        "cookie": "cookies",
        "host": "lambda-846800462-us-east-2.elb.amazonaws.com",
        "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6)",
        "x-amzn-trace-id": "Root=1-5bdb40ca-556d8b0c50dc66f0511bf520",
        "x-forwarded-for": "72.21.198.66",
        "x-forwarded-port": "443",
        "x-forwarded-proto": "https"
    },
    "isBase64Encoded": false,
    "body": "request_body"
}

response object

{
    "isBase64Encoded": false,
    "statusCode": 200,
    "statusDescription": "200 OK",
    "headers": {
        "Set-cookie": "cookies",
        "Content-Type": "application/json"
    },
    "body": "Hello from Lambda (optional)"
}

Multi Value Mode

request event

{
    "requestContext": {
        "elb": {
            "targetGroupArn": "arn:aws:elasticloadbalancing:region:123456789012:targetgroup/my-target-group/6d0ecf831eec9f09"
        }
    },
    "httpMethod": "GET",
    "path": "/",
    "multiValueQueryStringParameters": { "myKey": ["val1", "val2"] },
    "multiValueHeaders": {
        "accept": ["text/html,application/xhtml+xml"],
        "accept-language": ["en-US,en;q=0.8"],
        "content-type": ["text/plain"],
        "cookie": ["cookies"],
        "host": ["lambda-846800462-us-east-2.elb.amazonaws.com"],
        "user-agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6)"],
        "x-amzn-trace-id": ["Root=1-5bdb40ca-556d8b0c50dc66f0511bf520"],
        "x-forwarded-for": ["72.21.198.66"],
        "x-forwarded-port": ["443"],
        "x-forwarded-proto": ["https"]
    },
    "isBase64Encoded": false,
    "body": "request_body"
}

response object

{
    "isBase64Encoded": false,
    "statusCode": 200,
    "statusDescription": "200 OK",
    "multiValueHeaders": {
        "Set-cookie": ["cookies"],
        "Content-Type": ["application/json"]
    },
    "body": "Hello from Lambda (optional)"
}

Support APIGW v2 cookies response

see also: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html

response object

{
    "cookies" : ["cookie1", "cookie2"],
    "isBase64Encoded": true|false,
    "statusCode": httpStatusCode,
    "headers": { "headerName": "headerValue", ... },
    "body": "Hello from Lambda!"
}

@jordaneremieff
Copy link
Collaborator

Hi @araki-yzrh, thanks for the PR! I'll try to get to reviewing this soon and update the PR with any comments.

@jordaneremieff
Copy link
Collaborator

Hey @araki-yzrh! Sorry, my review has been a bit delayed, it might be a bit longer before I'm able to look this over. My personal life has been pretty demanding lately, but I do intend to review this when I find some good time.

@nathanglover
Copy link
Contributor

Anecdotally I can say this PR works as expected. I recently installed this fork of Mangum for a POC deploying Django on AWS lambda using ELB as the trigger and things seem to be working as expected.

Thank you @araki-yzrh and @jordaneremieff for working on this!

@gmachado-nextreason
Copy link

Worked here too. Installed the Mangum fork on FastAPI as dependency and deployed to AWS Lambda using ELB.
Any updates on the review? Glad to help if needed.

Thanks for the fork work.

@jordaneremieff jordaneremieff merged commit ded6a55 into Kludex:main Feb 13, 2021
@jordaneremieff
Copy link
Collaborator

@araki-yzrh great work, thanks!

four43 pushed a commit to four43/mangum that referenced this pull request Mar 27, 2021
* fix apigw v2 request cookie header

* add v1 cookie header test

* support elb

* support elb test

* refactored adapter event parsing

* fix elb single value headers response

* fix apigw v2 cookie response

* remove old code
four43 pushed a commit to four43/mangum that referenced this pull request Aug 20, 2021
* fix apigw v2 request cookie header

* add v1 cookie header test

* support elb

* support elb test

* refactored adapter event parsing

* fix elb single value headers response

* fix apigw v2 cookie response

* remove old code
khamaileon pushed a commit to khamaileon/mangum that referenced this pull request Jan 13, 2024
* fix apigw v2 request cookie header

* add v1 cookie header test

* support elb

* support elb test

* refactored adapter event parsing

* fix elb single value headers response

* fix apigw v2 cookie response

* remove old code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants