How to regularly clean up hung Fargate tasks

0

I have identical ECS clusters spread across several AWS regions. They are configured to run a short running fargate task on demand. Sometimes these tasks do not complete; they "hang" in the running state.

I'm going to figure out why that happens separately, what I'd like to do as a stopgap is to regularly purge tasks that have been running for longer than an hour for example.

It looks like I can do this with systems manager; run a script that goes and gets all running tasks from the cluster in each region, then stop those that have been running for too long. Will this work, and is there a better way to do this?

asked a year ago199 views
1 Answer
1
Accepted Answer

Sure, it's possible to have an external process like an SSM document or a lambda that finds and kills them. But I would probably only use the timeout util in the startup command when you start your app. https://linuxize.com/post/timeout-command-in-linux/

the command would look something like this: timeout 3600 start service.

Hope it helps!

profile picture
answered a year ago

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.

Guidelines for Answering Questions