You can use the docker ps command on your container instance to list the running containers. In the below example, only the Amazon ECS container agent is running. For more information, see docker ps in the Docker documentation.
You can enable Container Insights on all new clusters by default, or on an individual cluster as you create it. Open the Amazon ECS console at https://console.aws.amazon.com/ecs/ . In the navigation pane, choose Account Settings. Select the check box at the bottom of the page to enable the Container Insights default.
Q: What is responsible for starting and stopping tasks on an ECS Container instance. E: The ECS Agent is responsible for starting/stopping tasks. It also monitors tasks and resource utilization.
I figured this out after a few more hours of investigating. Amazon, if you are listening, you should state this somewhere in your management console when creating a cluster or adding instances to the cluster:
"Before you can add ECS instances to a cluster you must first go to the EC2 Management Console and create
ecs-optimized
instances with an IAM role that has theAmazonEC2ContainerServiceforEC2Role
policy attached"
Here is the rigmarole:
1. Go to your EC2 Dashboard, and click the Launch Instance
button.
2. Under Community AMIs
, Search for ecs-optimized
, and select the one that best fits your project needs. Any will work. Click next.
3. When you get to Configure Instance Details, click on the create new IAM role link
and create a new role called ecsInstanceRole
.
4. Attach the AmazonEC2ContainerServiceforEC2Role
policy to that role.
5. Then, finish configuring your ECS Instance.
NOTE: If you are creating a web server you will want to create a securityGroup to allow access to port 80.
After a few minutes, when the instance is initialized and running you can refresh the ECS Instances tab you are trying to add instances too.
Currently, the Amazon AWS web interface can automatically create instances with the correct AMI and the correct name so it'll register to the correct cluster.
Even though all instances were created by Amazon with the correct settings, my instances wouldn't register. On the Amazon AWS forums I found a clue. It turns out that your clusters need internet access and if your private VPC does not have an internet gateway, the clusters won't be able to connect.
The fix
In the VPC dashboard you should create a new Internet Gateway and connect it to the VPC used by the cluster. Once attached you must update (or create) the route table for the VPC and add as last line
0.0.0.0/0 igw-24b16740
Where igw-24b16740 is the name of your freshly created internet gateway.
I ran into this issue when using Fargate. I fixed it when I explicitly defined launchType="FARGATE"
when calling run_task
.
Other suggested checks
Selecting the suggested AMI which was specified for the given region solved my problem.
To find out the AMI - check Launching an Amazon ECS Container Instance.
By default all the ec2 instances are added to default cluster . So the name of the cluster also matters.
See point 10 at Launching an Amazon ECS Container Instance.
More information available in this thread.
Just in case someone else is blocked with this problem as I was... I've tried everything here and didn't work for me.
Besides what was said here regards the EC2 Instance Role, as commented here, in my case only worked if I still configured the EC2 Instance with simple information. Using the User Data an initial script like this:
#!/bin/bash
cat <<'EOF' >> /etc/ecs/ecs.config
ECS_CLUSTER=quarkus-ec2
EOF
Informing the related ECS Cluster Name created at this ecs config file, resolved my problem. Without this config, the ECS Agent Log at the EC2 Instance was showing an error that was not possible to connect to the ECS, doing this I've got the EC2 Instance visible to the ECS Cluster.
After doing this, I could get the EC2 Instance available for my EC2 Cluster:
The AWS documentation said that this part is optional, but in my case, it didn't work without this "optional" configuration.
When this happens, you need to look to the following:
AmazonEC2ContainerServiceforEC2Role
managed policy attached to itecs-optimized
(you can check this in EC2 dashboard)Most of the time, this issue appears because of the misconfigured VPC. According to the Documentation:
QUOTE: If you do not have an interface VPC endpoint configured and your container instances do not have public IP addresses, then they must use network address translation (NAT) to provide this access.
These are the reasons why you don't see the EC2 instances listed in the ECS dashboard.
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