DEV Community

Wakeup Flower
Wakeup Flower

Posted on

sidecar container in ECS

A sidecar container is just another container that runs alongside your main application container inside the same ECS Task (or Pod in Kubernetes).
It’s a way to add extra functionality without touching your main app container.

Think of it like a sidecar on a motorcycle 🚲 — it’s attached to the main thing and helps it do extra work.


Why Use a Sidecar Container?

Containers should be immutable — meaning you don’t install extra software inside them while they run.
If you need monitoring, logging, security scanning, etc., instead of modifying your main container, you deploy those features as a separate container inside the same ECS Task.
They share the same network and storage if needed.


Example in ECS

Imagine your ECS Task runs a web app container.
You want logging and monitoring. Instead of adding that inside your app container, you add a sidecar container that runs those tools.

Diagram

ECS Task
│
├── app-container   <-- your main application
│
└── sidecar-container   <-- monitoring/logging/patching tools
Enter fullscreen mode Exit fullscreen mode

Why This is Useful

  • Isolation: the app and monitoring run independently.
  • No app changes: you don’t rebuild app container for monitoring.
  • Easier updates: you can update the sidecar without touching the app.
  • Shared resources: they can share volumes and network namespaces.

Example YAML (ECS Task Definition)

containerDefinitions:
  - name: app-container
    image: myapp:latest
    essential: true
    logConfiguration:
      logDriver: awslogs
      options:
        awslogs-group: /ecs/my-app

  - name: monitoring-agent
    image: my-monitoring-agent:latest
    essential: false
    logConfiguration:
      logDriver: awslogs
      options:
        awslogs-group: /ecs/my-app-monitoring
Enter fullscreen mode Exit fullscreen mode

Here:

  • app-container = your main app
  • monitoring-agent = sidecar doing extra tasks
+-----------------------------------------+
|            ECS Task Definition         |
|                                         |
|  +----------------+   +--------------+ |
|  | app-container  |   | sidecar      | |
|  | (your main     |   | container    | |
|  | application)   |   | (monitoring, | |
|  |                |   | logging, etc)| |
|  +----------------+   +--------------+ |
|                                         |
|  Shared Network & Volumes              |
+-----------------------------------------+
Enter fullscreen mode Exit fullscreen mode

Key points:

  • Both containers live inside the same ECS Task.
  • They can share storage volumes and network resources.
  • The sidecar container runs alongside the main container without modifying it.
  • This is the AWS best practice for adding extra features like monitoring, logging, or security without rebuilding your application.

Top comments (0)