Sub topic 8
Reshaping events with input transformers
An input transformer rewrites the event for one target after a rule has matched it. This chapter covers how paths and templates work, how quoting behaves, and the mistakes that break deliveries. It assumes you can create a rule and attach a target (the previous chapters), read JSON, and use the AWS CLI or boto3.
Why reshape an event
A matched event arrives at the target as the full envelope: version, id, detail-type, source, account, time, region, resources, and detail. Many targets want less than that. A queue consumer may need only an order ID and an amount. An SNS email needs a readable sentence. An API destination may expect a specific body shape.
You have three ways to control what a target receives. Each target uses at most one of them.
| Setting | What the target receives | Use it when |
|---|---|---|
| (none) | The whole event | The consumer understands the envelope |
| `InputPath` | The part of the event at one JSON path, such as `$.detail` | You want a subtree unchanged |
| `Input` | A fixed JSON text, ignoring the event | The event is only a trigger |
| `InputTransformer` | A new document built from event fields | You need to pick, rename, or combine fields |
The transformer runs after matching. It never changes which events a rule selects, and it never changes what other targets on the same rule receive. Each target has its own transformer.
How a transformer works
An input transformer has two parts.
InputPathsMapis a map from variable names to JSON paths in the event. A path starts with$and uses dots and array indexes, for example$.detail.customer.emailor$.detail.items[0].sku. Wildcards and filters are not supported. You can define up to 100 variables.InputTemplateis the output text, up to 8,192 characters. You insert a variable by writing its name in angle brackets, such as<orderId>.
Take this event:
{
"version": "0",
"id": "6a7e8feb-b491-4cf7-a9f1-bf3703467718",
"detail-type": "OrderPlaced",
"source": "com.example.orders",
"account": "123456789012",
"time": "2026-11-26T18:42:38Z",
"region": "us-east-1",
"resources": [],
"detail": {
"orderId": "1001",
"amount": 250,
"status": "new",
"customer": { "email": "[email protected]" }
}
}With the target definition from the earlier example, the paths map extracts orderId as "1001" and amount as 250. The template {"orderId": <orderId>, "amount": <amount>} then produces:
{"orderId": "1001", "amount": 250}The SQS queue receives that small document instead of the full envelope.
Reserved variables
You can use some variables in a template without defining them in the paths map. Their names start with aws.events, so do not use that prefix for your own names.
<aws.events.rule-name>is the name of the rule that matched.<aws.events.rule-arn>is that rule's ARN.<aws.events.event.ingestion-time>is the time EventBridge received the event.<aws.events.event.json>is the entire original event as JSON.
These help with traceability. Adding the rule name to every message lets a consumer see which rule routed it without a lookup.
Attaching a transformer
The same target can be written in boto3, where Python handles the JSON escaping for you:
import boto3
events = boto3.client("events")
response = events.put_targets(
Rule="high-value-orders",
EventBusName="orders-bus",
Targets=[
{
"Id": "order-alerts-queue",
"Arn": "arn:aws:sqs:us-east-1:123456789012:order-alerts",
"InputTransformer": {
"InputPathsMap": {
"orderId": "$.detail.orderId",
"amount": "$.detail.amount",
"email": "$.detail.customer.email",
},
"InputTemplate": (
'{"orderId": <orderId>, "amount": <amount>, '
'"email": <email>, "rule": <aws.events.rule-name>}'
),
},
}
],
)
if response["FailedEntryCount"] > 0:
for entry in response["FailedEntries"]:
print(entry["ErrorCode"], entry["ErrorMessage"])PutTargets can succeed as a call while individual targets fail, so the script checks FailedEntryCount and reads FailedEntries. In the CLI JSON file, the template is a string, so every inner double quote needs a backslash, as in the targets.json example from the spine. Most template mistakes are escaping mistakes.
Quoting rules
Quoting is the part of templates that surprises people most. The behavior depends on the shape of the template.
- If the template is a JSON object, place variables where a JSON value goes, without quotes. A string value is inserted with its quotes, a number as a number, and an object or array as JSON. In the example above,
<orderId>becomes"1001"and<amount>becomes250. - If the template is plain text, wrap the whole template in quotes to make the output a JSON string, for example
"Order <orderId> for <amount> was placed". For a text-based target such as an SNS email, this gives you a readable sentence. - If you want a variable inside a longer string within a JSON object, put it inside that string's quotes:
{"message": "Order <orderId> placed"}.
Embedding a variable that holds an object inside a quoted string produces text that is not valid JSON, so keep object-valued variables in value position.
A text template for notifications
For an SNS topic that sends email, a text template works well. You can build one from the same events:
{
"Id": "order-email",
"Arn": "arn:aws:sns:us-east-1:123456789012:order-notices",
"InputTransformer": {
"InputPathsMap": {
"orderId": "$.detail.orderId",
"amount": "$.detail.amount",
"time": "$.time"
},
"InputTemplate": "\"Order <orderId> for <amount> was placed at <time>.\""
}
}The subscriber receives Order 1001 for 250 was placed at 2026-11-26T18:42:38Z. as the message body.
Common errors
- Invalid template.
PutTargetsrejects a template that references a variable not in the paths map and not reserved. The error appears inFailedEntries, not as a CLI failure, so check it. - Wrong path for the field. Event fields live under
detail. Writing$.orderIdinstead of$.detail.orderIdgives an empty value, as the warning above explains. - Mixing settings. A target cannot carry
Input,InputPath, andInputTransformertogether. Pick one. - Invalid JSON output. Targets such as API destinations and Step Functions parse the body. A stray comma or an unquoted variable inside a string breaks the document, and the delivery fails. Failed deliveries follow the retry policy and dead-letter queue settings from the next chapter, so a bad template can end up in your DLQ.
- Losing needed context. If a consumer later needs a field you dropped, you cannot recover it from the message. When in doubt, include
<aws.events.event.json>as a field so the original event travels along. - Array and path limits. Paths are fixed. You can read
$.detail.items[0], but you cannot loop over all items. Do that work in the consumer.
Choosing between a transformer and consumer code
A transformer is cheap and needs no code, but it is limited to extracting fields and filling templates. It cannot compute, branch, or loop. Use it to trim and rename. When you need logic, send the full event to a Lambda function and do the work there. A transformer also keeps your consumer independent of the envelope, so a queue worker can read {"orderId", "amount"} without knowing it came from EventBridge.
Exercise
An event has detail.customer.email. Write the InputPathsMap and InputTemplate that send only {"email": "<address>"} as JSON, where the address is a string value. Then say what happens if the path is written as $.customer.email.
Show answer
InputPathsMap: {"email": "$.detail.customer.email"}. InputTemplate: {"email": <email>}. The string value is inserted with its quotes automatically in a JSON object template. With $.customer.email, the path matches nothing because the field lives under detail, so the variable is empty and the target receives a document without the address, while the delivery itself still goes ahead.
Exercise
A rule has one SQS target and one SNS target. You add an input transformer to the SQS target only. What does the SNS target receive?
Show answer
The full, unmodified event. A transformer belongs to a single target, so it changes only what that target receives.