Taha Sharafat
Taha Sharafat

Reputation: 1

How to gracefully shutdown Amazon ECS Fargate task?

Problem: Fargate tasks are being shut down without completing the processes within the task upon scaling in. (Auto Scaling implemented)

Is there a possibility for the Fargate task to exit gracefully (to complete all the processes within the task before shutting it down)?

There is a way in EC2 to handle this through Life cycle hooks but I'm not sure if there is anything similar in the Amazon Fargate cluster.

Upvotes: 0

Views: 5926

Answers (2)

scyldinga
scyldinga

Reputation: 41

In 2022 AWS introduced the Task scale-in protection endpoint.

The following task scale-in protection endpoint path is available to containers: $ECS_AGENT_URI/task-protection/v1/state

Upvotes: 3

Niklas Ekman
Niklas Ekman

Reputation: 961

Capture the SIGTERM signal and do your cleanup in there. You can trap it in your application, using whatever programming language that you want, or trap it in a shell entrypoint script.

For more information see this blogpost from AWS.

Upvotes: 1

Related Questions