GeezerVison is showing github.com — Feature request: Parser schema for `ECS Task State Change` EventBridge events · Issue #5927 · aws-powertools/powertools-lambda-typescript
Feature request: Parser schema for ECS Task State Change EventBridge events #5927DescriptionUse case
Amazon ECS sends an ECS Task State Change event to EventBridge whenever a task changes state. A common pattern is a rule on stopped tasks that invokes a Lambda function to alert on, enrich, or record why the task stopped.
The Parser has EventBridgeSchema and EventBridgeEnvelope, but detail is z.unknown(), so each such function writes its own schema for the ECS payload. That is easy to get wrong, because the available sources disagree about which fields a stopped task's event has:
- Docs: the two example events in the ECS developer guide, both
RUNNING tasks.
- Registry: the
aws.ecs@ECSTaskStateChange schema in the EventBridge schema registry.
- Real events: 7 stopped Fargate tasks captured in
eu-central-1.
| Field |
Docs |
Registry |
Real events |
stopCode, stoppedReason, stoppedAt |
Not shown |
Optional |
Always |
containers[].exitCode |
Not shown |
Optional |
Only when the container started |
group |
Shown |
Optional |
Always |
enableExecuteCommand, ephemeralStorage |
Shown |
Missing |
Always |
capacityProviderName |
Shown |
Missing |
Absent for tasks run with launchType |
computeId |
Not shown |
Missing |
Always |
aws/containers-roadmap#2907 has the full comparison and asks ECS to document the fields and update the registry schema.
Solution/User Experience
A new packages/parser/src/schemas/ecs.ts, laid out like the Amazon Connect Outbound Campaigns schema (#5502), exporting:
| Export |
Use |
EcsTaskStateChangeDetailSchema |
The detail object, with EventBridgeEnvelope |
EcsTaskStateChangeSchema |
The whole event: EventBridgeSchema.extend() with source: z.literal('aws.ecs'), 'detail-type': z.literal('ECS Task State Change'), and the detail |
import { parse } from '@aws-lambda-powertools/parser';
import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes/eventbridge';
import { EcsTaskStateChangeDetailSchema } from '@aws-lambda-powertools/parser/schemas/ecs';
export const handler = async (event: unknown) => {
const task = parse(event, EventBridgeEnvelope, EcsTaskStateChangeDetailSchema);
if (task.lastStatus === 'STOPPED') {
// task.stopCode, task.stoppedReason, task.containers[0]?.exitCode, ...
}
};
Proposed field rules:
- Required: the fields the registry schema requires, which every real event had:
clusterArn, containers, createdAt, desiredStatus, lastStatus, overrides, taskArn, taskDefinitionArn, updatedAt, version.
- Optional: everything else, including the stop fields, since a
RUNNING task's event has none of them.
- Timestamps:
z.iso.datetime(), like EventBridgeSchema's time.
- Unknown fields: a plain
z.object(), not .strict(), so a field the schema doesn't list, such as computeId today, doesn't fail parsing.
Test events would be the two documented examples (Fargate and EC2) plus captured stopped-task events: an essential container that exited with code 1, an image that couldn't be pulled, and a secret that couldn't be fetched.
Because this would be the first schema for an AWS service event delivered through EventBridge rather than a direct Lambda trigger, it's worth agreeing where such schemas live before adding more. ECS Container Instance State Change and ECS Deployment State Change would be natural follow-ups in the same file.
I'm happy to open the PR once the approach is agreed.
Alternative solutions
- A schema in each function, passed with
EventBridgeEnvelope. It works, but repeats a field list that is easy to get wrong.
- EventBridge code bindings (
aws schemas get-code-binding-source). They generate TypeScript types from the registry schema, but give no runtime validation and inherit its missing fields.
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand. Activitypowertools-for-aws-oss-automation commented on Nov 10, 2026 Warning This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either reopen the issue, or open a new issue referencing this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|