How do I change my container instance type in Amazon ECS?

Last updated: 2019-07-23

How can I change the container instance type in my Amazon Elastic Container Service (Amazon ECS) cluster?

Short Description

To change your container instance type, complete the steps in one of the following sections:

  • Update container instances launched in an ECS cluster through the AWS CloudFormation stack
  • Update container instances launched manually in an ECS cluster

Resolution

Update container instances launched in an ECS cluster through the AWS CloudFormation stack

Important: The following steps apply only to ECS clusters created with resources that internally create an underlying AWS CloudFormation stack. The stack has a name in the following format: EC2ContainerService-yourClusterName. These steps don't apply to empty ECS clusters or to customized approaches for provisioning container instances.

Update the value of the EcsInstanceType parameter in the AWS CloudFormation stack:

  1. Open the AWS CloudFormation console.
  2. Select the stack that contains your ECS cluster.
    Note: The cluster name is appended to the end of your stack name (for example, EC2ContainerService-yourClusterName).
  3. Choose Actions, and then choose Update Stack.
  4. Choose Use current template, and then choose Next.
  5. For EcsInstanceType, set a value that's appropriate for the instance type in your container instance, and then choose Next.
  6. Skip the Options section, choose Next, and then choose Update.

Replace the old container instances in the cluster:

  1. To update the AWS CloudFormation stack, complete steps 1-4 in the preceding section.
  2. For AsgMaxSize, enter a parameter value that's double the current size.
    Note: For example, if the current value is 2, set the new value to 4. This helps prevent downtime when you change the instance type.
  3. Open the Amazon ECS console.
  4. In the navigation pane, choose Clusters, and then choose your cluster.
  5. Choose the ECS Instances tab, and then select the container instance IDs for the old container instances that you want to replace.
    Note: If DeploymentConfiguration allows for replacement tasks to be placed on container instances, Amazon ECS places the replacement tasks automatically.
  6. Choose the Actions menu, and then choose Drain instances to drain the instances.
  7. On the ECS Instances tab, verify that Running tasks count is 0 for your old container instances.
  8. In the navigation pane, choose Clusters, and then select your cluster.
  9. Choose the ECS Instances tab, select the container instance IDs of your old container instances, and then choose Deregister.
    Note: Deregistering an instance removes it from Amazon ECS.
  10. In your AWS CloudFormation template, set the value of AsgMaxSize to the original value to terminate the older container instances.
    Important: This step assumes that your Auto Scaling group has the Default Termination Policy.

Update container instances launched manually in an ECS cluster

  1. Copy the launch configuration of your Auto Scaling group, and then name your new launch configuration.
  2. Change your instance type.
  3. In the Amazon EC2 console, in the Auto Scaling section of the navigation pane, choose Auto Scaling Groups. Then, select the Auto Scaling group for your container instance.
  4. Choose Actions, and then choose Edit.
  5. In the pop-up window, for Launch Configuration, choose the launch configuration that you created in step 1 of this section.
  6. For Desired Capacity, enter a value that's double the size of the current value, and then update the value of Max as needed.
    Note: Desired capacity must be between minimum and maximum group size, inclusive.
  7. In the navigation pane of the Amazon ECS console, choose Clusters, and then choose your cluster.
  8. Choose the ECS Instances tab, select the container instance IDs for the old container instances that you want to replace.
  9. Choose the Actions menu, and then choose Drain instances to drain the instances.
  10. On the ECS Instances tab, for your old container instances, verify that Running tasks count is 0.
  11. Choose the ECS Instances tab, select the container instance IDs for your old container instances, and then choose Deregister.
    Note: Deregistering an instance removes it from Amazon ECS.
  12. In the Amazon EC2 console, in the Auto Scaling section of the navigation pane, choose Auto Scaling Groups.
  13. Choose Actions, and then choose Edit.
  14. In your Auto Scaling group configuration, set Desired Capacity and Max to their original values, and then save your changes.
    Note: This terminates the old container instances in the ECS cluster. 

Did this article help you?

Anything we could improve?


Need more help?