Skip to content

How to capture ECS retirement notice AWS_ECS_TASK_PATCHING_RETIREMENT with Event Bridge and SNS

0

We use ECS Fargate for hosting customer application, from time to time we see Fargate apps restarted from aws ecs maintenance events

We want to create an Event Bridge Rule to capture the 14 day retirement notice following this example: https://aws.amazon.com/blogs/containers/improving-operational-visibility-with-aws-fargate-task-retirement-notifications/

We created an event bridge rule (in python cdk stack) with the following pattern that forwards details to SNS message. We have success receiving other ECS notifications, but have not seen any notices for "AWS_ECS_TASK_PATCHING_RETIREMENT".

EventPattern(
  source=["aws.health"],
  region=["us-east-1"],
  detail_type=["AWS Health Event],
  detail={
    "service": ["ECS]
  }
)

It has been more than 4 months since the rule was created, and last week we saw restart events initiated by aws for ecs task maintenance.

Could you please advise on the correct EventPattern to capture events for AWS_ECS_TASK_PATCHING_RETIREMENT and AWS_ECS_TASK_RETIREMENT_SCHEDULED?

2 Answers
5

Hi,

You can use the below pattern which you can pretty much construct from the console (screenshot below) using the predefined values.

{
  "source": ["aws.health"],
  "detail-type": ["AWS Health Event"],
  "detail": {
    "service": ["ECS"],
    "eventTypeCategory": ["scheduledChange"],
    "eventTypeCode": ["AWS_ECS_TASK_PATCHING_RETIREMENT", "AWS_ECS_TASK_RETIREMENT_SCHEDULED"]
  }
}

Enter image description here

AWS
SUPPORT ENGINEER

answered 2 years ago

EXPERT

reviewed 2 years ago

EXPERT

reviewed 2 years ago

  • Thank you for suggestion, I see both your example and Leo K example does not have region, perhaps that is my mistake in my EventPattern, I will compare and try out

1

I think the below should work (in raw event pattern syntax for EventBridge). Note that you'll need the EventBridge rule separately in every region where you have ECS tasks.

{
  "detail-type": ["AWS Health Event"],
  "detail": {
    "service": ["ECS"],
    "eventTypeCode": ["AWS_ECS_TASK_RETIREMENT_SCHEDULED", "AWS_ECS_TASK_PATCHING_RETIREMENT"]
  }
}
EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

EXPERT

reviewed 2 years ago

  • Thank you. Trying to compare and know the reason my event pattern above didn't work. Is the reason because the "source" value should not be "aws.health"?

  • I don't know which region your ECS tasks are in, but you never need to filter based on region, because ECS only emits the events in the region where the tasks reside. Your events wouldn't arrive if your EventBridge rule is in a different region from ECS, or if the rule is attached to an event bus other than the default event bus, or if the region filter in the event pattern doesn't match the region of the ECS tasks and the EventBridge rule. In general, I'd prefer to keep only the essential fields in the filter, to make it easier to read and troubleshoot.

  • @Leo K Thanks for explanation, will try your example

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.