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?

已提问 2 年前203 查看次数
1 回答
1
已接受的回答

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
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则