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

Bug: Kinesis Firehose SQS Record schema should fail parsing if data is invalid #3249

Open
dreamorosi opened this issue Oct 23, 2024 · 2 comments
Labels
bug Something isn't working confirmed The scope is clear, ready for implementation parser This item relates to the Parser Utility

Comments

@dreamorosi
Copy link
Contributor

Expected Behavior

As per title, when working with a Kinesis Firehose event that contains a SQS event in the data field, if the field is not a valid SQS event the entire parsing should fail.

Current Behavior

Currently if this happens, the parsing is successful and the data is returned as-is.

Code snippet

N/A

Steps to Reproduce

N/A

Possible Solution

The schema should be modified from this:

const KinesisFirehoseSqsRecordSchema = KinesisFireHoseRecordBase.extend({
  data: z.string().transform((data) => {
    try {
      return SqsRecordSchema.parse(
        JSON.parse(Buffer.from(data, 'base64').toString('utf8'))
      );
    } catch (e) {
      return data;
    }
  }),
});

to something like this:

const KinesisFirehoseSqsRecordSchema = KinesisFireHoseRecordBase.extend({
  data: z.string().transform((data, ctx) => {
    try {
      return SqsRecordSchema.parse(
        JSON.parse(Buffer.from(data, 'base64').toString('utf8'))
      );
    } catch (e) {
      ctx.addIssue({
        code: z.ZodIssueCode.custom,
        message: 'Failed to parse SQS record',
        fatal: true,
      });

      return z.NEVER;
    }
  }),
});

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

20.x

Packaging format used

npm

Execution logs

No response

@dreamorosi dreamorosi added bug Something isn't working confirmed The scope is clear, ready for implementation parser This item relates to the Parser Utility labels Oct 23, 2024
@dreamorosi dreamorosi moved this from Triage to Backlog in Powertools for AWS Lambda (TypeScript) Oct 23, 2024
@dreamorosi
Copy link
Contributor Author

While working on this, if picked up after #3248, remove change the corresponding unit test from it.fails to it in the packages/parser/tests/unit/schema/kinesis-firehose.test.ts file.

@svozza
Copy link
Contributor

svozza commented Nov 30, 2024

Happy to pick this up if you want. Seems like a very straightforward change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed The scope is clear, ready for implementation parser This item relates to the Parser Utility
Projects
Development

No branches or pull requests

2 participants