ECS task definition is not configured with a health check Affecting ECS service in AWS


Severity

0.0
medium
0
10
    Severity Framework
    Snyk CCSS
    Rule category
    Containers / Health

Is your enviroment affected by this misconfiguration?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
    Frameworks
  • Snyk ID SNYK-CC-00187
  • credit Snyk Research Team

Description

Adding a health check to your ECS task definitions ensures that it is still operational and gives you more control in monitoring the health of your tasks. It also enables the host to kill and reschedule tasks that are no longer operational.

How to fix?

In the container_definitions attribute, set healthcheck to a command that determines whether the container is healthy.

Example Configuration

resource "aws_ecs_task_definition" "valid_container_healthcheck" {
  family = "valid_container_healthcheck"

  container_definitions = <<EOF
[
  {
    "name": "valid_container_healthcheck",
    "image": "hello-world",
    "memory": 128,
    "healthcheck": {
      "command": ["CMD-SHELL", "echo 'healthy' || exit 1"]
    }
  }
]
EOF

  requires_compatibilities = ["EC2"]
}