To collect logs from the ECS container instance automatically, we can use the Amazon ECS logs collector script.
Here, at Bobcares, we assist our customers with several AWS queries as part of our AWS Support Services.
Today, let us discuss how we can do this.
Collect logs from ECS container instance automatically
With Amazon ECS logs collector we can collect general OS logs as well as Docker and Amazon ECS container agent logs.
Generally, it supports the following operating systems:
- Amazon Linux
- Red Hat Enterprise Linux 7
- Debian 8
- Ubuntu 14.04
- Windows 2016
How to Collect Logs automatically?
Moving ahead, let us see how our Support Techs perform this query for our customers.
Download and run the Amazon ECS logs collector for Linux
1. Initially, we connect to the container instance.
2. In order to confirm the installation of curl, we run:
curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3
We need to install the curl package if the command doesn’t return the results.
3. Eventually, we download the Amazon ECS logs collector script:
4. Then to collect the logs and create an archive with the script, we run:
[ec2-user ~]$ sudo bash ./ecs-logs-collector.sh
Once we run the script, we can examine the logs in the collect folder. In the folder, we’ll find the collect.tgz file, a compressed archive of all the logs.
Download and run the Amazon ECS logs collector for Windows
1. First, we connect to the container instance.
2. To download the script, we open Windows PowerShell with administrator privileges, and run:
Invoke-WebRequest -OutFile ecs-logs-collector.ps1 https://raw.githubusercontent.com/awslabs/aws-ecs-logs-collector-for-windows/master/ecs-logs-collector.ps1
3. In the same window, to collect the logs and create the archive, we run:
Once we run the script, we can examine the logs in the collect folder. The script creates this folder.
Run the Amazon ECS logs collector in debug mode for Windows
Assume, the logs don’t provide all the information that we need. In that case, we can enable debug logging for the Docker daemon and Amazon ECS container agent with the -RunMode debugs option.
This will allow the script to collect the logs before enabling debug mode.
The script restarts the Docker daemon and Amazon ECS agent and then terminates all containers running on the instance.
However, before we proceed we need to drain the container instance and move any important tasks to other container instances.
To enable debug mode, run the following command using Windows PowerShell with administrator privileges:
.\ecs-logs-collector.ps1 -RunMode debug
[Need help with the log collection? We’d be happy to assist you]
In short, we saw how our Support Techs go about automatically collecting logs from ECS container instances.