Skip to content

Bug: SqsRecordSchema incorrectly precludes null value for md5OfMessageAttributes #4631

@ajpower

Description

@ajpower

Expected Behavior

When an SQS queue's event source mapping is configured with a maxBatchingWindow, the md5OfMessageAttributes of the individual Records will be null. The SqsRecordSchema should parse such records.

Current Behavior

The SqsRecordSchema fails to parse records with null md5OfMessageAttributes, returning the error

Expected string, received null at "Records[0].md5OfMessageAttributes"

Code snippet

Create a Lambda handler using the S3SqsEventSchema defined below:

const S3TestEventSchema = z.object({
    Event: z.literal('s3:TestEvent'),
    Bucket: z.string(),
});
const S3EventRecordsSchema = S3Schema.transform((val) => val.Records[0]);
const S3EventSchema = z.union([S3EventRecordsSchema, S3TestEventSchema]);
const S3SqsEventRecordSchema = SqsRecordSchema.extend({
    body: JSONStringified(S3EventSchema),
});

export const S3SqsEventSchema = z.object({
    Records: z.array(S3SqsEventRecordSchema).nonempty(),
});

In our case, we are processing S3 events sent to an SQS queue. But the issue should be reproducible for any event type.

Steps to Reproduce

Create a Lambda function to process an SQS queue whose event source mapping includes a maxBatchingWindow.

Possible Solution

Allow md5OfMessageAttributes to be nullable:

md5OfMessageAttributes: z.string().optional().nullable(),

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

20.x

Packaging format used

npm

Execution logs

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingparserThis item relates to the Parser Utilitypending-releaseThis item has been merged and will be released soon

Type

No type

Projects

Status

Coming soon

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions