Search code examples
amazon-ecsamazon-cloudwatch

How to determine the Cloudwatch log stream for a ECS service per date


I've got an ECS Cluster service running with a task, and can view its Cloudwatch log streams using the AWS console.

How a set date for awslogs-stream-prefix because I want to recognize logs stream by date by date.

  "containerDefinitions": [
    {
      "dnsSearchDomains": null,
      "logConfiguration": {
        "logDriver": "awslogs",
        "secretOptions": null,
        "options": {
          "awslogs-group": "/ecs/my-task-definition",
          "awslogs-region": "us-east-1",
          "awslogs-stream-prefix": "ecs"
        }

Solution

  • Unfortunately it is not possible to configure awslogs driver to have awslogs-stream-prefix as date.

    Log stream is created at the time of task creation, and below is a snippet which describes the options and recommendation as per AWS[ 1, 2 ] & Docker Docs [ 1 ] regarding awslogs driver.

    The awslogs-stream-prefix option allows you to associate a log stream with the specified prefix, the container name, and the ID of the Amazon ECS task to which the container belongs. If you specify a prefix with this option, then the log stream takes the following format:

    prefix-name/container-name/ecs-task-id

    If you do not specify a prefix with this option, then the log stream is named after the container ID that is assigned by the Docker daemon on the container instance. Because it is difficult to trace logs back to the container that sent them with just the Docker container ID (which is only available on the container instance), we recommend that you specify a prefix with this option.

    For Amazon ECS services, you could use the service name as the prefix, which would allow you to trace log streams to the service that the container belongs to, the name of the container that sent them, and the ID of the task to which the container belongs.

    If you would like to just have the creation date of the steam, you can have it on AWS CloudWatch Console while reviewing logs by adding the column for the same.

    CloudWatch Console> Log Groups > Settings Icon on top right corner > check the Creation Time