Skip to content

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

Closed
@dreamorosi

Description

@dreamorosi

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcompletedThis item is complete and has been merged/shippedparserThis item relates to the Parser Utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions