Refreshing ECS Container Instance
This guide explains how to refresh an ECS container instance when it becomes disconnected from the ECS service. This is different from restarting containers - this addresses issues with the underlying EC2 instance that hosts the containers.
When to Refresh Container Instance
You may need to refresh the ECS container instance in the following situations: - Container instance shows as "DISCONNECTED" in the ECS console - Tasks fail to start with capacity or connectivity issues - Container instance appears unhealthy or unresponsive - ECS agent has stopped communicating with the ECS service - After network connectivity issues or EC2 instance problems
Understanding the Difference
Container Restart vs Container Instance Refresh: - Container Restart: Stops and starts application containers (see Restarting ECS Containers) - Container Instance Refresh: Restarts the underlying EC2 instance that hosts the containers
Prerequisites
- Access to AWS Console with ECS and EC2 permissions
- Understanding that this will cause downtime for all running containers on the instance
- Coordination with team members if this affects production services
Step-by-Step Process
1. Identify the Disconnected Container Instance
- Access ECS Console: Navigate to AWS Console → ECS
- Select Cluster: Click on
Odoo_ECS_Cluster - Container Instances Tab: Click on the "Container instances" tab
- Check Status: Look for instances with status:
DISCONNECTED- Instance is not communicating with ECSINACTIVE- Instance is not accepting new tasksUNHEALTHY- Instance is experiencing issues
2. Note Running Tasks (Important)
Before refreshing the instance: 1. Check Running Tasks: Note which tasks are currently running on the instance 2. Service Impact: Understand which services will be affected 3. Backup Plan: Ensure other instances can handle the workload if needed
3. Access the EC2 Instance
- Get Instance ID: In the container instance details, note the EC2 instance ID
- Navigate to EC2: Go to AWS Console → EC2
- Find Instance: In the EC2 dashboard, locate the instance by its ID
- Verify Instance: Confirm this is the correct instance by checking:
- Instance ID matches
- Instance type and configuration
4. Stop the EC2 Instance
- Select Instance: Check the box next to the EC2 instance
- Instance State: Click "Instance state" dropdown
- Stop Instance: Select "Stop instance"
- Confirm: Confirm the stop action when prompted
- Wait for Stop: Wait for the instance state to change to "Stopped"
5. Start the EC2 Instance
- Select Stopped Instance: Ensure the instance is selected
- Instance State: Click "Instance state" dropdown
- Start Instance: Select "Start instance"
- Monitor Startup: Watch the instance state change to "Running"
- Check Status Checks: Wait for both system and instance status checks to pass
6. Verify ECS Agent Reconnection
- Return to ECS Console: Navigate back to ECS →
Odoo_ECS_Cluster - Container Instances: Check the container instances tab
- Verify Status: Confirm the instance status is now:
ACTIVE- Instance is healthy and accepting tasks- Connected and communicating with ECS service
- Check Agent Version: Verify ECS agent is running the correct version
7. Monitor Task Restart
- Automatic Task Restart: ECS will automatically restart tasks that were running
- Check Services: Go to the Services tab and verify
odoo-httpservice - Monitor Tasks: Watch for new tasks to start and reach
RUNNINGstatus - Verify Health: Ensure application health checks pass
Troubleshooting
If Instance Won't Start
- Check EC2 Limits: Verify you haven't hit EC2 instance limits
- Review Security Groups: Ensure security groups allow proper communication
- Check Subnets: Verify subnet has available IP addresses
- Instance Health: Check if the instance has underlying health issues
If ECS Agent Won't Connect
- Check IAM Roles: Verify the instance has proper ECS permissions
- Network Connectivity: Ensure the instance can reach ECS endpoints
- ECS Agent Logs: Check EC2 instance logs for ECS agent errors
- Agent Version: Verify ECS agent is up to date
If Tasks Don't Restart
- Service Configuration: Check if service has desired task count set
- Resource Limits: Verify instance has enough CPU/memory
- Task Definition: Ensure task definition is valid
- Placement Constraints: Check if any constraints prevent task placement
Alternative Methods
Using AWS CLI
# Stop EC2 instance
aws ec2 stop-instances --instance-ids i-1234567890abcdef0
# Wait for instance to stop
aws ec2 wait instance-stopped --instance-ids i-1234567890abcdef0
# Start EC2 instance
aws ec2 start-instances --instance-ids i-1234567890abcdef0
# Wait for instance to be running
aws ec2 wait instance-running --instance-ids i-1234567890abcdef0
Quick Reference
- Cluster:
Odoo_ECS_Cluster - Service:
odoo-http - Process: EC2 Console → Stop Instance → Start Instance
- Verification: ECS Console → Container Instances → Check ACTIVE status
- Related Docs: Restarting ECS Containers, Accessing CloudWatch Logs