aws / aws/aws-cdk

(aws-events-targets): (Add support for Predefined variables for Input transformers)

Open
#27,841 3 comments 3 reactions 0 assignees View on GitHub
@aws-cdk/aws-events-targets effort/small feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

Currently there is no available feature to make use of [Predefined variables](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html#eb-transform-input-predefined).

**AWSEventField** would work the same way as **EventField** but for the **AWS Predefined variables** ( `aws.events.rule-arn`, `aws.events.event.json`, `aws.events.rule-name`, `aws.events.event.ingestion-time`, `aws.events.event` ).

### Use Case

Without **Predefined variables** available in CDK, we need to keep deploying changes to the input transformer, and keep manually adding attributes with RuleTargetInput.

When we could instead just use `aws.events.event.json` to add the original event and then add the additional metadata but rigth now there is no option to use **Predefined variables** at all.

### Proposed Solution

For example this code:
```typescript
import { RuleTargetInput, AWSEventField } from "aws-cdk-lib/aws-events";

const ruleTargetInput = RuleTargetInput.fromObject({
// Currently this does not work, it is configured as a Constant rather than as an Input Transformer.
// ruleName: "",
// originalEvent: "",
// This new feature would make it possible:
ruleName: AWSEventField.ruleName,
originalEvent: AWSEventField.eventJSON ,
});
```
Would generate the following stack template (an empty object input map and an input template with only Predefined variables):
```json
{
"Arn": {
"Fn::GetAtt": ["function", "Arn"]
},
"Id": "Target0",
"InputTransformer": {
"InputPathsMap": { },
"InputTemplate": "{\"ruleName\":,\"originalEvent\":}"
}
}
```

### Other Information

https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html#eb-transform-input-predefined

### Acknowledgements

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

2.104.0

### Environment details (OS name and version, etc.)

Windows 10

Contributor guide

Open the contributing guide

Research direction

Start with the aws-events RuleTargetInput and EventField entry points described in the issue, then trace how fromObject produces an InputTransformer. Define how AWSEventField should represent each listed AWS predefined variable, and verify synthesis against the provided template with an empty InputPathsMap.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.