How can I capture stdout of an AWS ECS Fargate container to send logs to Loki?

I currently have several AWS ECS Fargate services with tasks that write their logging to stdout. Those log statements are automatically sent to CloudWatch. I want to send the same logging statements to Grafana Loki instead of CloudWatch using Alloy.

The services all write to stdout to avoid any potential disk-space issues that could be encountered when writing logs to files. I need help with config.alloy as well as task definitions for both the main apps as well as an alloy sidecar container.

Our focus right now is getting logs to Grafana cloud, but we later want traces and metrics as well.

Any guidance would be much appreciated.

Because you can’t get to the host for ECS Fargate, you can’t get access to the stdout logs.

I think your best solution is to use fluentbit sidecar and set the log driver to fluentd, then configure fluentbit to send to either an alloy agent that proxies to loki, or to loki directly.

Here is an example for configuring fluentbit on ECS Fargate: Example Amazon ECS task definition: Route logs to FireLens - Amazon Elastic Container Service