Skip to main content

How to Connect to AWS Fargate

This guide provides step-by-step instructions on how to connect to an AWS Fargate instance.

Prerequisites

1. Install AWS CLI

Follow the official AWS documentation to install the AWS CLI: AWS CLI Installation Guide

2. Configure AWS CLI

Run the following command in your terminal:

aws configure

You'll be prompted to enter:

AWS Access Key ID
AWS Secret Access Key
Default region name (usually us-east-1, but confirm in your ECS Fargate service)
Default output format (can be left blank)

also you have to install Session Manager Plugin

Steps to Connect

  • Step 1: Access AWS Management Console Open your web browser Navigate to AWS Management Console Log in with your credentials

  • Step 2: Navigate to ECS Dashboard In the AWS Management Console, find and click on "Services" Under "Containers", select "Elastic Container Service"

  • Step 3: Locate Your Service In the ECS dashboard, find the "Clusters" section Select your cluster Navigate to the "Services" tab Find and click on your desired service

  • Step 4: Access Task Information In your service details, go to the "Tasks" tab Identify the task you want to connect to Note down the Task ID (you'll need this for the connection command)

  • Step 5: Connect to Fargate Instance Use the following AWS CLI command to connect:

aws ecs execute-command \
--cluster [YOUR_CLUSTER_NAME] \
--task [TASK_ARN] \
--container [CONTAINER_NAME] \
--interactive \
--command "/bin/bash"
Replace the placeholders:

[YOUR_CLUSTER_NAME]: Your ECS cluster name [TASK_ARN]: The full ARN of the task [CONTAINER_NAME]: The name of the container within the task Example:

aws ecs execute-command \
--cluster app-cluster \
--task arn:aws:ecs:us-east-1:767398094892:task/app-cluster/76903f32996c439db62c7eec93c88858 \
--container web_server \
--interactive \
--command "/bin/bash"

If successful, you'll now have an interactive bash session within your Fargate container.

Troubleshooting

If you encounter issues:

Verify your AWS CLI configuration:

aws configure list Ensure you have the necessary permissions in your AWS account

Check if the task is in the RUNNING state in the ECS console

Confirm that your VPC and security group settings allow the connection

Use AWS ECR EXEC CHECKER

Note

Always ensure you have the appropriate permissions and follow your organization's security protocols when accessing Fargate instances.

  • You can also use the script inside of infra folder called fargat.sh