Introduction

Sidecar containers support the main application container (for logging, proxying, monitoring). When a sidecar fails, it can cause the entire task to stop if marked as essential, or leave the application without its supporting services if it crashes silently.

Symptoms

Task stopped due to sidecar:

```bash $ aws ecs describe-tasks --cluster my-cluster --tasks abc123

"containers": [ { "name": "nginx-sidecar", "lastStatus": "STOPPED", "exitCode": 1, "reason": "Essential container in task exited" } ] ```

Sidecar keeps restarting:

```bash $ aws ecs describe-tasks --cluster my-cluster --tasks abc123 \ --query 'tasks[*].containers[*].[name,lastStatus,exitCode]'

["envoy-sidecar", "RUNNING", null] ["app", "STOPPED", 137] # Killed when sidecar failed ```

Application can't reach sidecar:

```bash $ kubectl logs app-container

Error: connect ECONNREFUSED 127.0.0.1:8200 # Sidecar not running ```

Common Causes

  1. 1.Sidecar marked essential - Fails entire task when sidecar exits
  2. 2.Startup order issues - App starts before sidecar ready
  3. 3.Resource contention - Sidecar consumes all CPU/memory
  4. 4.Health check failures - Sidecar marked unhealthy
  5. 5.Configuration errors - Wrong environment variables or config
  6. 6.Dependency on external services - Sidecar can't reach required services
  7. 7.Image pull failures - Sidecar image doesn't exist or access denied

Step-by-Step Fix

  1. 1.Check logs for specific error messages
  2. 2.Verify configuration settings
  3. 3.Test network connectivity
  4. 4.Review recent changes
  5. 5.Apply corrective action
  6. 6.Verify the fix

Step 1: Identify Container Status

```bash # Get all container statuses in task aws ecs describe-tasks --cluster my-cluster --tasks abc123 \ --query 'tasks[*].containers[*].[name,lastStatus,exitCode,reason]'

# Essential containers stop the entire task if they fail # Non-essential containers can fail without stopping the task ```

Step 2: Check Essential Flag

```bash # Get task definition aws ecs describe-task-definition --task-definition my-task:1 \ --query 'taskDefinition.containerDefinitions[*].[name,essential]'

# If sidecar is marked "essential: true", task stops when sidecar fails # Consider setting "essential: false" for sidecars ```

Update task definition:

bash
# Register new task definition with essential=false for sidecar
aws ecs register-task-definition \
  --family my-task \
  --container-definitions '[
    {
      "name": "app",
      "image": "my-app",
      "essential": true
    },
    {
      "name": "sidecar",
      "image": "my-sidecar",
      "essential": false
    }
  ]'

Step 3: Configure Container Dependencies

For startup order control:

```bash # Add dependsOn to ensure sidecar starts first aws ecs register-task-definition \ --family my-task \ --container-definitions '[ { "name": "app", "image": "my-app", "essential": true, "dependsOn": [ { "containerName": "sidecar", "condition": "HEALTHY" } ] }, { "name": "sidecar", "image": "my-sidecar", "essential": true } ]'

# Conditions: # - START: Container started # - COMPLETE: Container exited with code 0 # - SUCCESS: Container exited with code 0 (same as COMPLETE) # - HEALTHY: Container passed health check ```

Step 4: Add Health Checks to Sidecar

bash
# Add health check to sidecar
aws ecs register-task-definition \
  --family my-task \
  --container-definitions '[
    {
      "name": "sidecar",
      "image": "my-sidecar",
      "essential": true,
      "healthCheck": {
        "command": ["CMD-SHELL", "curl -f http://localhost:8200/health || exit 1"],
        "interval": 30,
        "timeout": 5,
        "retries": 3,
        "startPeriod": 60
      }
    }
  ]'

Step 5: Check Sidecar Logs

```bash # Get sidecar logs from CloudWatch aws logs get-log-events \ --log-group-name /ecs/my-task/sidecar \ --log-stream-name ecs/sidecar/TASK_ID

# Or via ECS Exec aws ecs execute-command \ --cluster my-cluster \ --task abc123 \ --container sidecar \ --command "cat /var/log/sidecar.log" \ --interactive

# Common issues in logs: # - Permission denied: Volume mount or file access issue # - Connection refused: Can't reach required service # - Out of memory: Resource limits too low ```

Step 6: Verify Resource Allocation

```bash # Check task resources aws ecs describe-task-definition --task-definition my-task:1 \ --query 'taskDefinition.containerDefinitions[*].[name,cpu,memory,memoryReservation]'

# Sidecar needs adequate resources: # - Envoy proxy: 32-128 CPU, 64-256 MB memory # - Fluentd: 64-256 CPU, 128-512 MB memory # - StatsD exporter: 16-64 CPU, 32-128 MB memory

# Increase if needed aws ecs register-task-definition \ --family my-task \ --container-definitions '[ { "name": "sidecar", "cpu": 128, "memory": 256, "memoryReservation": 128 } ]' ```

Step 7: Check Network Configuration

```bash # Sidecars use localhost to communicate with app # Verify both containers are in same network namespace

# For awsvpc mode (Fargate), containers share network namespace # For bridge mode, use links or network mode

# Verify sidecar can reach app on localhost aws ecs execute-command \ --cluster my-cluster \ --task abc123 \ --container sidecar \ --command "curl -s http://localhost:8080/health"

# If using bridge mode, may need to link containers # In task definition: "links": ["app:app"] ```

Step 8: Debug Sidecar Configuration

bash # Check environment variables aws ecs describe-task-definition --task-definition my-task:1 \ --query 'taskDefinition.containerDefinitions[?name==sidecar`].environment'

# Check secrets aws ecs describe-task-definition --task-definition my-task:1 \ --query 'taskDefinition.containerDefinitions[?name==sidecar].secrets'

# Verify secrets exist aws secretsmanager get-secret-value --secret-id my-sidecar-config ```

Step 9: Test Sidecar Image

```bash # Pull and test sidecar image locally docker pull my-sidecar:latest docker run -it my-sidecar:latest sh

# Test with environment variables docker run -it \ -e SIDECAR_CONFIG=value \ my-sidecar:latest

# Check if image exists aws ecr describe-images \ --repository-name my-sidecar \ --image-ids imageTag=latest ```

Step 10: Handle Graceful Shutdown

```bash # Configure stop timeout for graceful shutdown aws ecs register-task-definition \ --family my-task \ --container-definitions '[ { "name": "sidecar", "image": "my-sidecar", "stopTimeout": 30 # Wait 30 seconds before killing } ]'

# Ensure sidecar handles SIGTERM # In sidecar code: process.on('SIGTERM', () => { console.log('Shutting down gracefully...'); server.close(() => process.exit(0)); }); ```

Common Sidecar Patterns

Sidecar TypePurposeEssential
Envoy/ProxyService meshYes (if required for app)
Fluentd/Fluent BitLog forwardingNo
StatsD/PrometheusMetricsNo
Vault AgentSecretsYes (if app requires secrets)
nginxReverse proxyYes

Verification

```bash # After updating task definition, update service aws ecs update-service \ --cluster my-cluster \ --service my-service \ --task-definition my-task:NEW_VERSION \ --force-new-deployment

# Monitor task status aws ecs describe-tasks --cluster my-cluster --tasks NEW_TASK_ID \ --query 'tasks[*].containers[*].[name,lastStatus]'

# All containers should show RUNNING ```

  • [Fix AWS ECS Task Stuck in Pending](/articles/fix-aws-ecs-task-pending)
  • [Fix AWS ECS Service Not Scheduling](/articles/fix-aws-ecs-service-not-scheduling)
  • [Fix AWS ECS Exec Command Not Working](/articles/fix-aws-ecs-exec-command-not-working)
  • [AWS troubleshooting: Fix IAM Permission Denied - Complete Tro](fix-iam-permission-denied)
  • [AWS cloud troubleshooting: AWS ACM Certificate Pending Validation Because the](aws-acm-certificate-pending-validation-wrong-route53-zone)
  • [AWS cloud troubleshooting: AWS ALB Returns 502 Because the Target Closed the ](aws-alb-502-target-closed-connection-keepalive-timeout-mismatch)
  • [AWS cloud troubleshooting: Fix AWS ALB CreateListener TargetGroupNotFound Err](aws-alb-createlistener-targetgroupnotfound)
  • [AWS cloud troubleshooting: Fix Aws Alb Lambda 502 Bad Gateway Issue in AWS](aws-alb-lambda-502-bad-gateway)

<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "TechArticle", "headline": "Fix AWS ECS Sidecar Container Failed", "description": "Troubleshoot ECS sidecar container failures. Fix essential flag, startup dependencies, health checks, and container issues.", "url": "https://www.fixwikihub.com/fix-aws-ecs-sidecar-container-failed", "publisher": { "@type": "Organization", "name": "FixWikiHub", "url": "https://www.fixwikihub.com" }, "author": { "@type": "Person", "name": "FixWikiHub Editorial Team" }, "datePublished": "2026-04-01T18:36:29.673Z", "dateModified": "2026-04-01T18:36:29.673Z" } </script>