Skip to content

Conversation

heitorlessa
Copy link
Contributor

Issue #, if available: #797

Description of changes:

Parser incorrectly expected body to always be non-empty; this addresses it.

Actual event tested to repro #797

{
    "body": null,
    "resource": "/users",
    "path": "/users",
    "httpMethod": "GET",
    "headers": {
        "Accept": "*/*",
        "CloudFront-Forwarded-Proto": "https",
        "CloudFront-Is-Desktop-Viewer": "true",
        "CloudFront-Is-Mobile-Viewer": "false",
        "CloudFront-Is-SmartTV-Viewer": "false",
        "CloudFront-Is-Tablet-Viewer": "false",
        "CloudFront-Viewer-Country": "NL",
        "Host": "a1c2k0n4x4.execute-api.eu-west-1.amazonaws.com",
        "User-Agent": "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
        "Via": "2.0 b619a16f6f8fe9793bf642d2a8434284.cloudfront.net (CloudFront)",
        "X-Amz-Cf-Id": "sj5uo2ZyuF8WvtxH6IYxHMQFHCuMWaD-xE5T-7WFZR28Jz-Kp4Zvsw==",
        "X-Amzn-Trace-Id": "Root=1-618ff3e6-6e0fdf4f4197d0e7437264dd",
        "X-Forwarded-For": "83.41.50.10, 54.200.158.122",
        "X-Forwarded-Port": "443",
        "X-Forwarded-Proto": "https"
    },
    "multiValueHeaders": {
        "Accept": [
            "*/*"
        ],
        "CloudFront-Forwarded-Proto": [
            "https"
        ],
        "CloudFront-Is-Desktop-Viewer": [
            "true"
        ],
        "CloudFront-Is-Mobile-Viewer": [
            "false"
        ],
        "CloudFront-Is-SmartTV-Viewer": [
            "false"
        ],
        "CloudFront-Is-Tablet-Viewer": [
            "false"
        ],
        "CloudFront-Viewer-Country": [
            "NL"
        ],
        "Host": [
            "a1c2k0n4x4.execute-api.eu-west-1.amazonaws.com"
        ],
        "User-Agent": [
            "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
        ],
        "Via": [
            "2.0 b619a16f6f8fe9793bf642d2a8434284.cloudfront.net (CloudFront)"
        ],
        "X-Amz-Cf-Id": [
            "sj5uo2ZyuF8WvtxH6IYxHMQFHCuMWaD-xE5T-7WFZR28Jz-Kp4Zvsw=="
        ],
        "X-Amzn-Trace-Id": [
            "Root=1-618ff3e6-6e0fdf4f4197d0e7437264dd"
        ],
        "X-Forwarded-For": [
            "83.41.50.10, 54.200.158.122"
        ],
        "X-Forwarded-Port": [
            "443"
        ],
        "X-Forwarded-Proto": [
            "https"
        ]
    },
    "queryStringParameters": null,
    "multiValueQueryStringParameters": null,
    "pathParameters": null,
    "stageVariables": null,
    "requestContext": {
        "resourceId": "sfqe1d",
        "resourcePath": "/users",
        "httpMethod": "GET",
        "extendedRequestId": "IwMMEGaOjoEF_zw=",
        "requestTime": "13/Nov/2021:17:20:38 +0000",
        "path": "/Prod/users",
        "accountId": "231436140809",
        "protocol": "HTTP/1.1",
        "stage": "Prod",
        "domainPrefix": "a1c2k0n4x4",
        "requestTimeEpoch": 1636824038666,
        "requestId": "4fdd98f4-0570-46cb-b683-b0d02afe9dca",
        "identity": {
            "cognitoIdentityPoolId": null,
            "accountId": null,
            "cognitoIdentityId": null,
            "caller": null,
            "sourceIp": "83.41.50.10",
            "principalOrgId": null,
            "accessKey": null,
            "cognitoAuthenticationType": null,
            "cognitoAuthenticationProvider": null,
            "userArn": null,
            "userAgent": "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
            "user": null
        },
        "domainName": "a1c2k0n4x4.execute-api.eu-west-1.amazonaws.com",
        "apiId": "a1c2k0n4x4"
    },
    "isBase64Encoded": false
}

Checklist

Breaking change checklist

RFC issue #:

  • Migration process documented
  • Implement warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 13, 2021
@codecov-commenter
Copy link

codecov-commenter commented Nov 13, 2021

Codecov Report

Merging #820 (99d5370) into develop (e34469a) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #820   +/-   ##
========================================
  Coverage    99.90%   99.90%           
========================================
  Files          118      118           
  Lines         5107     5107           
  Branches       279      279           
========================================
  Hits          5102     5102           
  Misses           2        2           
  Partials         3        3           
Impacted Files Coverage Δ
...lambda_powertools/utilities/parser/models/apigw.py 100.00% <100.00%> (ø)
...mbda_powertools/utilities/parser/models/apigwv2.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e34469a...99d5370. Read the comment docs.

@heitorlessa heitorlessa changed the title fix(parser): apigw body can be null fix(parser): body and query strings can be null or omitted in apigw v1/v2 Nov 13, 2021
@heitorlessa heitorlessa added the bug Something isn't working label Nov 13, 2021
@heitorlessa
Copy link
Contributor Author

heitorlessa commented Nov 13, 2021

Same issue with API Gateway HTTP API v2 payload, including query strings.

payload where API GW v2 omit keys

{
    "version": "2.0",
    "routeKey": "GET /users",
    "rawPath": "/users",
    "rawQueryString": "",
    "headers": {
        "accept": "*/*",
        "content-length": "0",
        "host": "3mblkdfe53.execute-api.eu-west-1.amazonaws.com",
        "referer": "",
        "user-agent": "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
        "x-amzn-trace-id": "Root=1-618ffb41-0934497356e94b96397ed34e",
        "x-forwarded-for": "83.81.50.30",
        "x-forwarded-port": "443",
        "x-forwarded-proto": "https"
    },
    "requestContext": {
        "accountId": "231436140809",
        "apiId": "3mblkdfe53",
        "domainName": "3mblkdfe53.execute-api.eu-west-1.amazonaws.com",
        "domainPrefix": "3mblkdfe53",
        "http": {
            "method": "GET",
            "path": "/users",
            "protocol": "HTTP/1.1",
            "sourceIp": "83.81.50.30",
            "userAgent": "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
        },
        "requestId": "IwQyOgctDoEEJMA=",
        "routeKey": "GET /users",
        "stage": "$default",
        "time": "13/Nov/2021:17:52:01 +0000",
        "timeEpoch": 1636825921268
    },
    "isBase64Encoded": false
}

@heitorlessa heitorlessa changed the title fix(parser): body and query strings can be null or omitted in apigw v1/v2 fix(parser): body/QS can be null or omitted in apigw v1/v2 Nov 13, 2021
@heitorlessa heitorlessa merged commit 0728aa2 into aws-powertools:develop Nov 13, 2021
@heitorlessa heitorlessa deleted the fix/parser-apigw-null-body branch November 13, 2021 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants