I have an ECS task and I want to trigger a Lambda function once ECS task stopped. I created an event rule like below
{
"source": ["aws.ecs"],
"detail-type": ["ECS Task State Change"],
"detail": {
"clusterArn": ["arn:aws:ecs:region:account:cluster/mycluster"],
"taskDefinitionArn": ["arn:aws:ecs:region:account:task-definition/mytaskdefinition:revisionNumber"],
"lastStatus": ["STOPPED"]
}
}
This rule worked perfect when I used Default event bus, but as soon as I moved this event rule to a Custom Event bus, no events coming to that rule.
CodePudding user response:
AWS Events are emitted only to the default event bus. If you want to have them in a different event bus that you created, you need to create a Rule that forwards them there.
You would do this by creating a Rule
in your default event bus and use events_targets.EventBus
as the target to forward them to your custom event bus.
After you do this, you can create rules in the custom event bus to handle the events being forwarded there.
CodePudding user response:
Could you make sure the policies apply to the custom event bus to allow for the PutEvents action?
To manage permissions for an event bus, you can configure a resource-based policy for it. A resource-based policy specifies which events to allow, and which entities have permission to create or modify rules or targets for an event. For example, you can use a policy on an event bus to allow or deny events from sources.
The following example policy attached to an event bus named CustomBus1 allows the event bus to receive events from the same account and Region.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"events:PutEvents"
],
"Resource": [
"arn:aws:events:us-east-1:123456789:event-bus/CustomBus1"
]
}
]
}