Skip to content

Bug: SnsSchema parsing fails when Subject is null #3400

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
nied opened this issue Dec 4, 2024 · 5 comments · Fixed by #3415
Closed

Bug: SnsSchema parsing fails when Subject is null #3400

nied opened this issue Dec 4, 2024 · 5 comments · Fixed by #3415
Assignees
Labels
bug Something isn't working completed This item is complete and has been merged/shipped good-first-issue Something that is suitable for those who want to start contributing parser This item relates to the Parser Utility

Comments

@nied
Copy link

nied commented Dec 4, 2024

Expected Behavior

Sns events with a Subject that is null should pass schema parsing with SnsSchema.

Current Behavior

For an event like this:

{
  "Records": [
    {
      "EventSource": "aws:sns",
      "EventVersion": "1.0",
      "EventSubscriptionArn": "a subscription arn",
      "Sns": {
        "Type": "Notification",
        "MessageId": "a message id",
        "TopicArn": "an arn",
        "Subject": null,
        "Message": "hi there",
        "Timestamp": "2024-12-04T08:00:04.497Z",
        "SignatureVersion": "1",
        "Signature": "",
        "SigningCertUrl": "http://www.google.com",
        "UnsubscribeUrl": "http://www.google.com",
        "MessageAttributes": {}
      }
    }
  ]
}

The following fails:

import { SnsSchema } from '@aws-lambda-powertools/parser/schemas';

SnsSchema.parse(event)

This is due to Subject being null. It can be omitted or undefined, but in the case of null it seems to throw. However, it is a valid case for SNS to have Subject be null.

Code snippet

import { SnsSchema } from '@aws-lambda-powertools/parser/schemas';

SnsSchema.parse(
{
  "Records": [
    {
      "EventSource": "aws:sns",
      "EventVersion": "1.0",
      "EventSubscriptionArn": "a subscription arn",
      "Sns": {
        "Type": "Notification",
        "MessageId": "a message id",
        "TopicArn": "an arn",
        "Subject": null,
        "Message": "hi there",
        "Timestamp": "2024-12-04T08:00:04.497Z",
        "SignatureVersion": "1",
        "Signature": "",
        "SigningCertUrl": "http://www.google.com",
        "UnsubscribeUrl": "http://www.google.com",
        "MessageAttributes": {}
      }
    }
  ]
}
)

Steps to Reproduce

Run the codesnippet above and it should fail

Possible Solution

Allow the Subject field to be null as well as omitted

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

22.x

Packaging format used

npm

Execution logs

@nied nied added bug Something isn't working triage This item has not been triaged by a maintainer, please wait labels Dec 4, 2024
Copy link

boring-cyborg bot commented Dec 4, 2024

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

@am29d
Copy link
Contributor

am29d commented Dec 6, 2024

Hey Nies, thanks for opening the issue! While the fix is easy, I will take a closer look why we missed it in our tests.

Feel free to drop a PR, if you like, since you have spotted it first 😁.

@am29d am29d moved this from Triage to Backlog in Powertools for AWS Lambda (TypeScript) Dec 6, 2024
@am29d am29d added good-first-issue Something that is suitable for those who want to start contributing help-wanted We would really appreciate some support from community for this one confirmed The scope is clear, ready for implementation parser This item relates to the Parser Utility and removed triage This item has not been triaged by a maintainer, please wait labels Dec 6, 2024
@codyfrisch
Copy link

@am29d I just came here because this started happening to me. I'm almost willing to posit that AWS actually changed it because @types/aws-lambda is Subject?: string as well. I have no proof of course, I worked around it by sending a subject.

@dreamorosi dreamorosi moved this from Backlog to Working on it in Powertools for AWS Lambda (TypeScript) Dec 12, 2024
@dreamorosi dreamorosi self-assigned this Dec 12, 2024
@dreamorosi dreamorosi linked a pull request Dec 12, 2024 that will close this issue
@dreamorosi dreamorosi moved this from Working on it to Pending review in Powertools for AWS Lambda (TypeScript) Dec 12, 2024
@github-project-automation github-project-automation bot moved this from Pending review to Coming soon in Powertools for AWS Lambda (TypeScript) Dec 13, 2024
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 help-wanted We would really appreciate some support from community for this one confirmed The scope is clear, ready for implementation labels Dec 13, 2024
Copy link
Contributor

This is now released under v2.12.0 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 Dec 17, 2024
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 good-first-issue Something that is suitable for those who want to start contributing parser This item relates to the Parser Utility
Projects
Development

Successfully merging a pull request may close this issue.

4 participants