(aws-events-targets/EcsTask): Cannot pass the entire event to ECS task
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
Using the aws-events-targets/EcsTask class, I cannot pass the entire event. Which should be the default behavior.
A similair issue was raised in https://github.com/aws/aws-cdk/issues/15785
I don't think the input section of the rule should contain an empty json object by default since the ECS task wont get the payload of the event rule.
Maybe I missunderstood this class and I dont use it correctly.
My goal is to use the default event rule behavior and pass the entire rule event to the ECS Task, which is the default bheavior in other target types like aws lambda ( https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-events-targets/lib/lambda.ts#L8).
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Library Version
_No response_
### Expected Behavior
As stated in the `aws-events/RuleTargetConfig` interface, the default behavior should be the entire event https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-events/lib/target.ts#L113
### Current Behavior
The input section is automatically generated from this function https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-events-targets/lib/ecs-task.ts#L325 and result in an empty object of `containerOverrides` is empty.
```
Targets:
- Arn:
Fn::GetAtt:
- eventBusEcsTaskPaternscheduledfargateclusterBF03F136
- Arn
EcsParameters:
LaunchType: FARGATE
NetworkConfiguration:
AwsVpcConfiguration:
AssignPublicIp: DISABLED
SecurityGroups:
- Fn::GetAtt:
- eventBusEcsTaskPaternsecurityGroup1C7DA4F1
- GroupId
Subnets:
- subnet-0b81dac4c59ff9b88
- subnet-0baf828bb16b9c6d2
- subnet-0f2a0fec4166a49e0
TaskCount: 1
TaskDefinitionArn:
Ref: eventBusEcsTaskPaternecstasktargettaskdef7FCD529A
Id: Target0
Input: "{}"
RoleArn:
Fn::GetAtt:
- eventBusEcsTaskPaternecstasktargettaskdefEventsRole6C5990A7
- Arn
```
If I add `containerOverrides`, the input changes the JSON object that filters the event sent to ECS.
this.ecsTaskTarget = new EcsTaskTarget({
cluster: this.ecsCluster,
taskDefinition: this.taskDefinition,
assignPublicIp: false, // enforcé
launchType: LaunchType.FARGATE, // enforcé
securityGroups: [this.securityGroup.securityGroup],
subnetSelection: props.paramTargetEcsTask.paramVpc.selectSubnets({
subnetType: paramTaskSubnetType
}),
taskCount: paramDesiredTaskCount,
containerOverrides: [
{
containerName: 'test'
}
]
});
cdk diff output
```
[~] AWS::Events::Rule eventBusEcsTaskPatern/rule-CDK-TEST-s3-create-iaws-lab-event-bus-ecs eventBusEcsTaskPaternruleCDKTESTs3createiawslabeventbusecs87D7D6F4
└─ [~] Targets
└─ @@ -32,7 +32,7 @@
[ ] }
[ ] },
[ ] "Id": "Target0",
[-] "Input": "{}",
[+] "Input": "{\"containerOverrides\":[{\"name\":\"test\"}]}",
[ ] "RoleArn": {
[ ] "Fn::GetAtt": [
[ ] "eventBusEcsTaskPaternecstasktargettaskdefEventsRole6C5990A7",
```
### Reproduction Steps
- Create an event rule using `Rule` from aws-cdk-lib/aws-events
- Add a target using `EcsTask` from aws-cdk-lib/aws-events-targets
### Possible Solution
I will look into the L1 classes since the L2 class it seems impossible to pass the entire event to the ECS Task.
### Additional Information/Context
_No response_
### AWS CDK Library version (aws-cdk-lib)
2.185.0
### AWS CDK CLI version
2.1007.0
### Node.js Version
v18.20.4
### OS
linux
### Language
TypeScript
### Language Version
4.9.5
### Other information
_No response_
Contributor guide
Research direction
Start in packages/aws-cdk-lib/aws-events-targets/lib/ecs-task.ts around the input-generation function at line 325, then compare its behavior with RuleTargetConfig in packages/aws-cdk-lib/aws-events/lib/target.ts and the Lambda target in packages/aws-cdk-lib/aws-events-targets/lib/lambda.ts. Reproduce the Rule plus EcsTask case and inspect the L1 classes as suggested; done means the default target passes the entire event without an empty Input while containerOverrides still work.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100