Closed
Description
Expected Behavior
When working with the ApiGatewayEnvelope
and ApiGatewayV2Envelope
I should be able to extract the message body regardless of whether it's a plain text string, base64-encoded string, or a JSON-stringified one.
Current Behavior
When the message body is not a JSON-stringified object the envelope throws a runtime error as it's unable to parse it with JSON.parse()
.
Code snippet
import { z } from 'zod';
import { ApiGatewayEnvelope } from '@aws-lambda-powertools/parser/envelopes';
export const handler = async (event) => {
try {
ApiGatewayEnvelope.parse(event, z.string());
} catch (error) {
console.error(error);
}
}
Steps to Reproduce
Send a request with a body that is either plain text or an encoded binary.
Possible Solution
No response
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Shipped