Description
Use case
Hello,
For a long time now, we, like many others, have been using @types/aws-lambda
as our reference types for Lambda events. For safety, we used our own typeguard functions. Now that Powertools vends a parser, we'd like to start using it in our middleware. However, when working with the SQS event, I saw a type incompatibility around the md5OfMessageAttributes
field.
The @types/aws-lambda package defines it as such:
// SQS
// https://docs.aws.amazon.com/lambda/latest/dg/invoking-lambda-function.html#supported-event-source-sqs
export interface SQSRecord {
messageId: string;
receiptHandle: string;
body: string;
attributes: SQSRecordAttributes;
messageAttributes: SQSMessageAttributes;
md5OfBody: string;
md5OfMessageAttributes?: string;
eventSource: string;
eventSourceARN: string;
awsRegion: string;
}
The Powertools parser schema has it modeled like this:
/**
* Zod schema for a SQS record inside an SQS event.
*/
const SqsRecordSchema = z.object({
messageId: z.string(),
receiptHandle: z.string(),
body: z.string(),
attributes: SqsAttributesSchema,
messageAttributes: z.record(z.string(), SqsMsgAttributeSchema),
md5OfBody: z.string(),
md5OfMessageAttributes: z.string().optional().nullable(),
eventSource: z.literal('aws:sqs'),
eventSourceARN: z.string(),
awsRegion: z.string(),
});
Note the difference of md5OfMessageAttributes?: string
vs md5OfMessageAttributes: z.string().optional().nullable()
.
Solution/User Experience
The SQS or Lambda teams can probably best speak to whether null
is possible or it really should be string | undefined
. Depending on that answer, either the zod schema here should update or an update should be made to @types/aws-lambda
.
Going forward though, it would be nice if there were unit tests that compared the Zod schema parsed shapes against the types from @types/aws-lambda
. There are many libraries and utilities that have been written around the types from that package, so i t would be great if the parsed events from Powertools were compatible with those.
Alternative solutions
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status