Running Commands in ECS Containers with ECS Exec

To Nha Notes | Sept. 13, 2024, 9:29 a.m.

Amazon ECS Exec is a powerful feature that allows you to run commands and get a shell inside your running ECS containers. This makes it easier to debug issues, collect diagnostic information, and interact with your containerized applications.

Prerequisites

  • Make sure you have the ECS Exec feature enabled for your task definition or service. You can do this by setting the --enable-execute-command flag when creating or updating your task or service.
  • Ensure your IAM user or role has the necessary permissions to use ECS Exec, such as ecs:ExecuteCommand and ecs:DescribeTasks.

Running a Command

To run a command in your container, use the aws ecs execute-command CLI command:

aws ecs execute-command \
  --cluster <cluster-name> \
  --task <task-arn> \
  --container <container-name> \
  --interactive \
  --command "<command>"

Replace the placeholders with your specific cluster name, task ARN, container name, and the command you want to run.