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 #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