AWS ECS (Elastic Container Service) is a powerful container management service that simplifies the process of running, managing, and scaling Docker containers on AWS. Connecting to ECS containers is a crucial step in the deployment process, allowing users to interact with their applications and services seamlessly. In this guide, we will explore how to connect to AWS ECS containers in a few straightforward steps.
STEP 1: Attach SSM Policy to the existing ECS Task IAM role
Create the below SSM policy and attach it to the ECS Task IAM role, this policy will allow connection to ECS task using Session Manager Service (SSM).
Now create a new ECS Task IAM role with the above SSM policy and attach the role to the ECS task definition from dropdown as
STEP 2: Now on a remote machine from where we want to connect to the ECS container:
Now add the below IAM role policy for a User/AWS resource to execute ECS commands
Command to connect to ECS Fargate Container
aws ecs execute-command –cluster <cluster-name> --task <task-id> --container <container-name> --interactive --command "/bin/sh"