I want to change the container instance type in my Amazon Elastic Container Service (Amazon ECS) cluster.
Short description
To change your container instance type, take one of the following actions:
- Use the Amazon ECS console to update the container instance.
- Use AWS CloudFormation to update the container instance.
- Update the Amazon ECS cluster container instance.
After you change the container instance type, you must replace the previous container instances in your Amazon ECS cluster.
Resolution
Use the Amazon ECS console to update the container instance
Complete the following steps:
- Open the Amazon ECS console.
- In the navigation pane, choose Clusters.
- Select your cluster.
- Choose the Infrastructure tab, and then select the Amazon EC2 Auto Scaling group that's associated with your capacity provider.
- Choose the EC2 Auto Scaling group's launch template.
- Create a launch template version.
- For Instance type, choose the new launch template version.
- Update the Auto Scaling group with the new launch template version.
Use CloudFormation to update the container instance
Complete the following steps:
- Open the CloudFormation console.
- Select the stack that contains your Amazon ECS resources.
- Update your stack template for the stack that contains your resource to change the InstanceType value.
Note: After you change the InstanceType value, the AutoScalingReplacingUpdate policy generates a new launch template by default. CloudFormation also updates the Auto Scaling group to the latest version of the launch template. However, CloudFormation doesn't automatically replace the existing instances.
- Use change sets to update stacks, or directly update stacks.
Update the Amazon ECS cluster container instance
Complete the following steps:
- Open the Amazon ECS console.
- In the navigation pane, choose Clusters.
- Select your cluster.
- Choose the Infrastructure tab, and then select the Auto Scaling group that's associated with your capacity provider.
- Under Instance type requirements, select the Instance type.
If your Auto Scaling group gets the instance type from your launch template, then use the Amazon ECS console to update the container instance.
- Choose Update.
Replace the previous container instance
To reduce downtime for your application, scale additional instances before you drain the previous container instances.
Configure the following settings for your Auto Scaling group's desired capacity:
- For Desired capacity, enter a value that's double the existing value.
- For Max desired capacity, update the value to be larger than the Desired capacity value.
To replace the previous instance with a new instance, complete the following steps:
- Open the Amazon ECS console.
- In the navigation pane, choose Clusters.
- Select your cluster.
- Choose the Infrastructure tab.
- Under Container instances, select the ID for the previous container instance.
- Expand the Actions menu, and then choose Drain.
- Verify that Running tasks count is 0 for your previous container instance.
- Select the ID for the previous container instance, and then choose Deregister.
- Set Desired capacity and Max desired capacity to their original values, and then choose Save.
Note: If your Auto Scaling group has the default termination policy, then this action shuts down the previous container instances in the Amazon ECS cluster
Or, use an instance refresh to update instances in an Auto Scaling group.
Related information
Control which Auto Scaling instances terminate during scale in