Search code examples
amazon-web-servicesamazon-ecsamazon-cloudwatch

What's the proper way to forward ECS service logs to AWS CloudWatch?


So my understanding is that when I deploy a new service to ECS using AWS Copilot, logs are forwarded to CloudWatch automatically by default.

Copilot creates log groups for each service, I can see that in CloudWatch Logs.

However, according to AWS docs, logging can be also implemented using Copilot sidecars and AWS FireLens, which uses FluentD or FluentBit to collect logs, and then it forwards stuff CloudWatch.

I don't understand why is this necessary. I mean, why to create a sidecar for logging to CloudWatch, when logging seems to work automatically, without any sidecar.

https://aws.github.io/copilot-cli/docs/developing/sidecars/

There is an example here for logging via FireLens. What's the benefit of doing this over the logging mechanism that just works by default?

Thanks in advance!


Solution

  • AWS Copilot builds an image for you application that already has an agent configured to forward logs to CloudWatch, however you might want to deploy other images to ECS that don't have this agent installed. For example, suppose you wanted to deploy an nginx container to ECS, you might choose to use a sidecar to forward logs instead of customizing the nginx image.