Score:0

What defines the AWS ECS task re-creation timeout

cn flag

I have an AWS ECS Service with 2 REPLICA tasks in it. When I manually stop one of the tasks, the new one is created in almost exactly 5 minutes. Similar 5 minute timeout happens when one or more tasks get stopped due to a failure.

here is cloudformation definition of my service:

ServiceFrontend:
    Type: AWS::ECS::Service
    DependsOn:
        - LoadBalancerRule
    Properties:
        ServiceName: "my-service-frontend"
        Cluster:
            Fn::ImportValue: !Sub "${ProjectName}:${EnvType}:ClusterName"
        DeploymentConfiguration:
            MaximumPercent: 100
            MinimumHealthyPercent: 0
        DesiredCount: 2
        TaskDefinition: !GetAtt FrontendTaskStack.Outputs.TaskDefinition
        HealthCheckGracePeriodSeconds: 600
        ServiceRegistries:
            -   RegistryArn: !GetAtt 'DiscoveryService.Arn'
                ContainerName: !Sub "${ServiceName}-frontend"
                ContainerPort: !Ref 'FrontendContainerPort'
        LoadBalancers:
            -   ContainerName: !Sub "${ServiceName}-frontend"
                ContainerPort: !Ref 'FrontendContainerPort'
                TargetGroupArn: !Ref 'TargetGroup'
        PlacementStrategies:
            -   Field: 'memory'
                Type: 'binpack'
            -   Field: 'cpu'
                Type: 'binpack'

My question is: what defines this timeout? Can I control it? Or where can I see more insights in what is happening during those 5 mintues, because ECS service events only show how old task is deregistered and new one is registered again after 5 minutes, nothing in between.

enter image description here

If I change the same service and increase the desired tasks number - it starts provisioning new tasks in less than 30 seconds. How can I get the same recovery time when one of the tasks has stopped for some reason.

Googling and going through ECS docs doesn't seem to bring the answer. For context: this service has no autoscaling on service level, cluster's capacity provider has auto-scaling configured. But I don't think it is relevant here, as capacity provider doesn't start changing the capacity here.

Tomasz Kapłoński avatar
mx flag
Note that the 5 minute interval is does not start when the old instance is actually stopped but when the system starts draining connections. That would be grace period shutdown. The weird part is that it's 300 seconds but... for autoscalling groups - for containers it should be by default 30 seconds.
Tomasz Kapłoński avatar
mx flag
Anyway, the way to impact would be adjusting stop timeout or... handling termination signal properly on the main process in the container. See here for some concepts: https://aws.amazon.com/blogs/containers/graceful-shutdowns-with-ecs/
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.