Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to define a task timeout on AWS ECS?

I just need to know if there is any way to define a timeout while running tasks on AWS ECS Dockers

EDIT: I have tried setting the ECS_CONTAINER_STOP_TIMEOUT variable, but this is the timeout to kill the docker, I want a timeout to kill the task

like image 564
Renato Bibiano Avatar asked Jan 14 '19 12:01

Renato Bibiano


1 Answers

not at the moment, there's a feature request for that on:

https://github.com/aws/containers-roadmap/issues/291

ecs tasks are supposed to run your process/code without a time limit (compared to lambda where you have a 15 minutes timeout)

my first suggestion would be to run your docker in a lambda: https://aws.amazon.com/blogs/aws/new-for-aws-lambda-container-image-support/

if you can't or don't want to change... what you can do is configure a timeout function inside your application an call a stop-task cli action

you will need the cluster name or arn and task name or arn in your cli command

to have access to that from within your application, first enable container metadata

now you can query the agent endpoint:

curl http://localhost:51678/v1/metadata
curl http://localhost:51678/v1/tasks

make sure to check the metadata url for ec2 or fargate instances: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint.html

general actions:

  • [1] Enable Metadata: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-metadata.html
  • [2] Query Container Metadata for Cluster and Task Name or ARN
  • [3] Write a timeout function within your application and call aws ecs stop-task --cluster <value> --task <value> - https://docs.aws.amazon.com/cli/latest/reference/ecs/stop-task.html

Pros:

  • extremely cheap, you don't need extra resources from aws

Const:

  • you need to write/create the code for the timeout and integrate metadata etc
like image 167
oieduardorabelo Avatar answered Oct 20 '22 06:10

oieduardorabelo