Skip to content

Bug: APIGatewayRequestAuthorizerEventV2Schema has invalid definition for the identitySource field #3483

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
hibanka opened this issue Jan 16, 2025 · 5 comments · Fixed by #3485
Assignees
Labels
bug Something isn't working completed This item is complete and has been merged/shipped parser This item relates to the Parser Utility

Comments

@hibanka
Copy link

hibanka commented Jan 16, 2025

Expected Behavior

The identitySource field in APIGatewayRequestAuthorizerEventV2 can be null when the Lambda authorizer is not configured with an identity source (see screenshot from the AWS Console below).

Image

Current Behavior

The current definition does not account for this scenario, leading to an error:

identitySource: APIGatewayStringArray,

Image

Even the @types/aws-lambda package has invalid type definition:

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/01bf6ea3ae73629f4d488d777df91781e466ba15/types/aws-lambda/trigger/api-gateway-authorizer.d.ts#L38

Code snippet

APIGatewayRequestAuthorizerEventV2Schema.parse(event);

Steps to Reproduce

When creating a Lambda authorizer, do not specify an identity source.

Possible Solution

add .nullable()

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

20.x

Packaging format used

npm

Execution logs

@hibanka hibanka added bug Something isn't working triage This item has not been triaged by a maintainer, please wait labels Jan 16, 2025
@am29d
Copy link
Contributor

am29d commented Jan 17, 2025

Hey @hibanka , thanks for opening the issue, this makes sense, the docs even says the identity source is optional:

You can optionally specify identity sources for a Lambda authorizer.

Quick fix incoming...

Дякую!

@am29d am29d added parser This item relates to the Parser Utility and removed triage This item has not been triaged by a maintainer, please wait labels Jan 17, 2025
@am29d am29d moved this from Triage to Working on it in Powertools for AWS Lambda (TypeScript) Jan 17, 2025
@am29d am29d self-assigned this Jan 17, 2025
@am29d am29d added the confirmed The scope is clear, ready for implementation label Jan 17, 2025
@leandrodamascena
Copy link
Contributor

@am29d
Copy link
Contributor

am29d commented Jan 17, 2025

I just ran a quick test in the console, I can't reproduce an event with identitySource: null on API GW V2. @hibanka how did you configure the API GW?

Here is an example event I have got:

{
    "level": "INFO",
    "sampling_rate": 0,
    "service": "service_undefined",
    "timestamp": "2025-01-17T09:53:25.550Z",
    "xray_trace_id": "1-678a2895-213d6967651dc359012d63e3",
    "version": "2.0",
    "type": "REQUEST",
    "routeArn": "arn:aws:execute-api:eu-west-1:xxx:xxx/dev/GET/",
    "routeKey": "GET /",
    "rawPath": "/dev/",
    "headers": {
        "accept": "*/*",
        "accept-encoding": "gzip, deflate",
        "content-length": "0",
        "host": "xxx.execute-api.eu-west-1.amazonaws.com",
        "user-agent": "HTTPie/3.2.3",
        "x-amzn-trace-id": "Root=1-678a2895-2366ebd0602dd62318fec21f",
        "x-forwarded-for": "188.192.53.6",
        "x-forwarded-port": "443",
        "x-forwarded-proto": "https"
    },
    "requestContext": {
        "accountId": "xxxx",
        "apiId": "8x9ewplh90",
        "domainName": "xxx.execute-api.eu-west-1.amazonaws.com",
        "domainPrefix": "xxx",
        "http": {
            "method": "GET",
            "path": "/dev/",
            "protocol": "HTTP/1.1",
            "sourceIp": "188.192.53.6",
            "userAgent": "HTTPie/3.2.3"
        },
        "requestId": "EhtHagMOjoEEMLA=",
        "routeKey": "GET /",
        "stage": "dev",
        "time": "17/Jan/2025:09:53:25 +0000",
        "timeEpoch": 1737107605402
    }
}

I called the endpoint from my terminal via public URL.

Edit: nvm, we remove null values with the logger.

Copy link
Contributor

⚠️ COMMENT VISIBILITY WARNING ⚠️

This issue is now closed. Please be mindful that future comments 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.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added pending-release This item has been merged and will be released soon and removed confirmed The scope is clear, ready for implementation labels Jan 17, 2025
Copy link
Contributor

This is now released under v2.13.1 version!

@github-actions github-actions bot added completed This item is complete and has been merged/shipped and removed pending-release This item has been merged and will be released soon labels Jan 28, 2025
@dreamorosi dreamorosi moved this from Coming soon to Shipped in Powertools for AWS Lambda (TypeScript) Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completed This item is complete and has been merged/shipped parser This item relates to the Parser Utility
Projects
3 participants