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
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:
aws ecs stop-task --cluster <value> --task <value>
- https://docs.aws.amazon.com/cli/latest/reference/ecs/stop-task.html
Pros:
Const:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With