AWS Builder Center

Making Serverless Event Parsing More Reliable: My Contributions to AWS Powertools

How I fixed CloudFormation resource ID loss and added EventBridge WITH_METADATA support in Powertools for AWS Lambda (TypeScript), with Zod schema details, parsing examples, and validation tradeoffs.

A CloudFormation handler needs to know which resource it is updating or deleting. If event parsing removes that identifier before the handler receives it, a valid incoming request can become incomplete application input.
That was one of the problems I addressed while contributing to Powertools for AWS Lambda (TypeScript). A second contribution added support for EventBridge deliveries wrapped with metadata, so applications could validate those batches and extract typed business data through the Parser utility.
Both contributions were merged in October 2026. They focus on a boundary that serverless applications cross constantly: turning an external event into data application code can trust.

Why shared serverless tooling matters

 Powertools for AWS Lambda  provides utilities for common serverless concerns, including logging, tracing, metrics, idempotency, batch processing, and validation. The TypeScript implementation also works in JavaScript applications.
Its Parser utility combines runtime validation with inferred TypeScript types. That combination matters because a TypeScript type alone cannot validate an event arriving at runtime.
The project's  reference customer list  includes organizations such as Alma Media, Caylent, and LocalStack. This provides public evidence of adoption, although it does not establish how many individual engineers use Powertools or either of these specific changes.
The opportunity in contributing to a shared library is straightforward: a fix becomes available to other teams facing the same problem, instead of each team maintaining its own workaround.

Problem 1: CloudFormation parsing dropped the resource identifier

CloudFormation custom resources use a provider-defined  PhysicalResourceId  to identify a resource. Update and Delete requests include this field in the  custom resource request contract .
The Powertools schemas for those operations did not declare it. Parsing therefore dropped the field, even when it was present in the incoming event. A handler relying on the parsed result lost the identifier it needed to target the existing resource.
Consider this simplified view of the problem:
  • Incoming Update or Delete request: includes  PhysicalResourceId: "provider-defined-physical-id" .
  • Before the fix: the parsed result omits that field.
  • After the fix: the parsed result preserves it as a string; an absent or non-string value fails validation.
In  PR #5767 , I added the field to both schemas, updated the fixtures and examples, and added regression checks.

Why the field disappeared

These schemas use Zod objects, which strip unrecognized keys by default. The incoming request could contain the correct identifier and still lose it during parsing because the schema did not declare the field. A TypeScript assertion on the raw event would not change that runtime behavior.
The fix explicitly models the required field in both operation schemas. This excerpt shows the Delete schema:
const CloudFormationCustomResourceDeleteSchema = z.object({
...CloudFormationCustomResourceBaseSchema.shape,
RequestType: z.literal('Delete'),
PhysicalResourceId: z.string(),
});
The Update schema receives the same required string field. Keeping it required follows the service request contract and ensures invalid input fails at the parsing boundary.
For example, with a complete Delete request supplied as rawEvent:
import { CloudFormationCustomResourceDeleteSchema }
from '@aws-lambda-powertools/parser/schemas';

const event = CloudFormationCustomResourceDeleteSchema.parse(rawEvent);
const resourceId: string = event.PhysicalResourceId;
// The identifier is preserved and inferred as string.
The important part was the contract it restored. Application code using the parsed Update or Delete event can access the identifier with a matching inferred string type.
The tests check both sides of that contract: valid identifiers survive parsing, while missing values, nulls, and numeric values fail validation. Type assertions also check the inferred field type.
For teams maintaining custom resource handlers, this removes a gap between the AWS request format and the parsed event their code receives. It preserves an input that resource lifecycle logic needs.

Problem 2: EventBridge metadata deliveries needed a parsing path

An event's delivery format matters as much as its business payload. Code expecting a standard EventBridge event cannot simply assume that a delivery wrapped with metadata has the same shape.
In  PR #5776 , I added Parser support for EventBridge  WITH_METADATA  deliveries containing standard EventBridge events.
The contribution introduced metadata, record, and batch schemas with inferred types, alongside  EventBridgeWithMetadataEnvelope .
The envelope gives a batch a defined path into application code:
  1. Validate a nonempty batch of delivery records.
  1. Validate each wrapped EventBridge event.
  1. Parse each record's  Data.detail  using the application's schema.
  1. Return the parsed details in their original input order.
This makes reusable validation and extraction available through Powertools, reducing the custom parsing code a consumer would otherwise need to write.

Composing transport and application schemas

The envelope extends the record schema with an application-specific schema for the nested detail. The central validation and extraction expression is:
EventBridgeWithMetadataRecordSchema.extend({
Data: EventBridgeSchema.extend({ detail: schema }),
})
.array()
.nonempty()
.parse(data)
.map((record) => record.Data.detail);
This validates the delivery wrapper, standard EventBridge fields, and business payload before returning the details. System metadata requires an aws:DeliveryType of LIVE or REPLAY; the optional user Metadata field is a string-to-string map. Arbitrary PutRawEvents payloads are outside this schema's scope.
An application can use the envelope directly. Here, rawBatch represents the incoming WITH_METADATA array:
import { z } from 'zod';
import { EventBridgeWithMetadataEnvelope }
from '@aws-lambda-powertools/parser/envelopes';

const OrderSchema = z.object({
orderId: z.string(),
total: z.number().nonnegative(),
});

const result = EventBridgeWithMetadataEnvelope.safeParse(
rawBatch,
OrderSchema,
);

if (!result.success) {
// Retains the original input and wrapped parsing error.
// Apply the application's failure policy here.
throw result.error;
}

const orders: z.infer<typeof OrderSchema>[] = result.data;
// Only validated details are returned, in input order.
The envelope returns detail objects rather than delivery metadata. Use the record schema directly when the handler needs metadata as well.

Preserving precision and useful errors

Several details were important for correctness. Sequence numbers remain strings, avoiding numeric conversion that could lose precision. Validation errors retain paths relative to the original input, helping developers locate an invalid value within a batch. Transform failures retain their underlying error causes. The envelope wraps parsing failures in a ParseError, and safeParse returns a discriminated result with success, error, and originalEvent on failure. For a bad orderId in the second record, a validation issue can identify the path [1, "Data", "detail", "orderId"], instead of pointing only at an extracted payload.
The envelope also has a deliberate boundary: an invalid record fails validation of the whole batch. It is not a partial-failure batch processor. For a single delivery object, or when application code needs to retain delivery metadata, the record schema provides the appropriate building block.

Testing the behavior developers depend on

For these contributions, a successful happy-path parse was only part of the evidence. The checks also needed to cover rejected inputs, inferred types, and error behavior.
For the CloudFormation fix, the PR records successful parser tests, type checks, builds, lint, and the full pre-push check. Validation was local; it did not include an AWS deployment.
For the EventBridge addition, the PR records 368 tests and 13 type tests, alongside package consumer checks, builds, and lint. Documentation entries were added so developers could discover the new schemas and envelope.
The regression checks cover preserved fields, missing or incorrectly typed identifiers, empty batches, invalid nested details, input order, string sequence numbers, and transform errors. Type checks complement runtime tests by verifying the consumer-facing inferred types.

What I took away

Working on these changes reinforced a practical lesson: an event schema is part of an application's operational contract. A missing field can remove information a handler depends on. A delivery wrapper can require validation at more than one level before business logic can safely use the payload.
My contributions addressed those two boundaries: preserving CloudFormation resource identity and adding a reusable parsing path for EventBridge metadata batches.
For developers considering an open-source contribution, a useful starting point is a concrete mismatch between a documented service contract and library behavior. Reproduce it, define the expected result, and add a regression test that makes the contract explicit. A focused change can become a useful building block for the next team working through the same problem.
You can explore the implementation and review history in  the CloudFormation fix  and  the EventBridge Parser addition .
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article