aws / aws/amazon-cloudwatch-agent

Exit code 2 when Cloudwatch agent is almost immediately stopped

Open
#770 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
550
Forks
271
Avg merge
1d 21h
Merged PRs (30d)
13

Description

**Describe the bug**

I'm using Cloudwatch Agent as an ECS sidecar. I have a scenario where I spin up an ECS instance, and it almost immediately spins down doing no work and with no metrics emitted to the Cloudwatch Agent.

What I'm seeing is that when this happens, the Cloudwatch Agent Logstream is empty, and the Cloudwatch Agent container exits with Exit Code 2, causing my ECS task to be considered to have failed.

**Steps to reproduce**

Spin up an ECS instance with the Cloudwatch Agent as an ECS sidecar, and code that exits immediately with no metrics emitted to the Cloudwatch Agent.

**What did you expect to see?**

Cloudwatch Agent exit with exit code 0. Some logs indicating what the Agent has done.

**What did you see instead?**

Cloudwatch Agent exit with exit code 2. No logs indicating what the Agent has done.

**What version did you use?**

The current version from https://hub.docker.com/r/amazon/cloudwatch-agent, which appears to be 1.247359.1b252618.

**What config did you use?**

Config: {
"logs": {
"metrics_collected": {
"emf": {},
}
}
}

**Environment**

ECS sidecar

**Additional context**

NA

Contributor guide

Open the contributing guide

Research direction

No source file or test is named. Start by reproducing the ECS sidecar scenario with the provided EMF configuration and trace the immediate shutdown path that produces exit code 2. Done means the agent exits with code 0 and emits useful logs when stopped before metrics are produced.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, go
Domain
cloud, observability-sre
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.