events: using fromObject does not maintain keys in inputTransformer
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
creating a rule target using fromObject does not preserve the key names, but rather generates a key from the values in the input paths. using L1 CfnRule works as expected
```
import * as cdk from "aws-cdk-lib";
import * as events from "aws-cdk-lib/aws-events";
import * as targets from "aws-cdk-lib/aws-events-targets";
import * as sqs from "aws-cdk-lib/aws-sqs";
import { Construct } from "constructs";
export class BugfixEventbridgeStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
let inputPathsMap = {
myName: events.EventField.fromPath("$.detail.name"),
myUUID: events.EventField.fromPath("$.detail.uuid"),
};
const queue = new sqs.Queue(this, "myQueue");
new events.CfnRule(this, "myCFNrule", {
name: "myCFNrule",
eventPattern: {
source: ["aws.ec2"]
},
state: "ENABLED",
targets: [
{
arn: queue.queueArn,
id: "shared-sqs-cfn",
inputTransformer: {
inputTemplate: JSON.stringify(inputPathsMap),
inputPathsMap: inputPathsMap,
},
},
],
});
const cdkRule = new events.Rule(this, "myCDKrule", {
ruleName: 'myCDKrule',
eventPattern: {
source: ["aws.ec2"]
}
});
cdkRule.addTarget(new targets.SqsQueue(queue, {
message: events.RuleTargetInput.fromObject(inputPathsMap)
}));
}
}
```
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Version
_No response_
### Expected Behavior
InputPathsMap is the same for myCFNrule and myCDKrule, using the key/value pairs provided in inputPathsMap
### Current Behavior
using the L2 construct (fromObject), keys provided in inputPathsMap are overwritten with system-generated keys. from cdk synth:
```
myCFNrule:
Type: AWS::Events::Rule
Properties:
EventPattern:
source:
- aws.ec2
Name: myCFNrule
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- myQueue4FDFF71C
- Arn
Id: shared-sqs-cfn
InputTransformer:
InputPathsMap:
myName: $.detail.name
myUUID: $.detail.uuid
InputTemplate: '{"myName":"$.detail.name","myUUID":"$.detail.uuid"}'
Metadata:
aws:cdk:path: BugfixEventbridgeStack/myCFNrule
myCDKruleB18813AA:
Type: AWS::Events::Rule
Properties:
EventPattern:
source:
- aws.ec2
Name: myCDKrule
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- myQueue4FDFF71C
- Arn
Id: Target0
InputTransformer:
InputPathsMap:
detail-name: $.detail.name
detail-uuid: $.detail.uuid
InputTemplate: '{"myName":,"myUUID":}'
Metadata:
aws:cdk:path: BugfixEventbridgeStack/myCDKrule/Resource
```
### Reproduction Steps
run the code provided in issue description
### Possible Solution
_No response_
### Additional Information/Context
same issue occurs whether using events.RuleTargetInput.fromObject(inputPathsMap) or events.RuleTargetInput.fromText(JSON.stringify(inputPathsMap))
### CDK CLI Version
2.1004.0 (build f0ad96e)
### Framework Version
_No response_
### Node.js Version
v23.9.0
### OS
Windows
### Language
TypeScript
### Language Version
typescript@5.6.3, aws-cdk-lib@2.181.1
### Other information
_No response_
Contributor guide
Research direction
Start by running the TypeScript reproduction and comparing the synthesized InputTransformer for RuleTargetInput.fromObject and fromText with the CfnRule output. Trace the events.RuleTargetInput and targets.SqsQueue entry points, then add or update coverage so the provided inputPathsMap key names are preserved and the synthesized template matches the expected mapping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 64/100