4

I have an Eventbridge rule which trigger a lambda function every time a task crashed in the cluster PRODUCTION. The issue is that I want to monitor only tasks running in the specific service backendPRODUCTION. I didn't find any template specifying an ECS service with Eventbridge. How can I trigger my lambda function only for tasks running in the specific service backendPRODUCTION?

Thanks in advance!

{
  "source": ["aws.ecs"],
  "detail-type": ["ECS Task State Change", "ECS Container Instance State Change"],
  "detail": {
    "clusterArn": ["arn:aws:ecs:eu-west-3:xxxxxxxxxxxx:cluster/PRODUCTION"],
    "lastStatus": [
      "STOPPED"
    ],
    "stoppedReason": [
      "Essential container in task exited"
    ]
  }
}
Howins
  • 487
  • 1
  • 6
  • 18
  • Tasks and services are two different things in ECS. Which one do you want to configure an event for? – Paolo Feb 22 '22 at 14:16
  • Unfortunately both. I want to monitor only tasks launched by a specific service. – Howins Mar 14 '22 at 09:42

1 Answers1

1

Looking at the "Task state change events" examples here, I'm not seeing any way to determine if a task is part of a service or not. The best thing I can think of after looking at the examples is to use a specific value in the family attribute of your service's tasks, which gets reported in the group attribute in Event Bridge, and then filter on that.

Mark B
  • 183,023
  • 24
  • 297
  • 295