Skip to main content

How to SSH into a backend container?

AWS Exec is a new functionality that allows users to run an interactive shell or a single command against a container inside a task deployed on either Amazon EC2 or AWS Fargate. You can find more information about AWS Exec here.

Prerequisites

To use AWS Exec, you will need to install the additional SSM Session Manager plugin for AWS CLI. The installation guide is available here.

Usage

Unlike an SSH bastion, AWS Exec does not create a new, separate task, but instead connects to an existing, running container. Therefore, you need to specify the CLUSTER_NAME, TASK_ID, and CONTAINER_NAME in your commands.

Here's an example command that allows you to run an interactive shell inside a selected container:

aws-vault exec <SELECTED_AWS_VAULT_PROFILE> -- aws ecs execute-command --cluster <CLUSTER_NAME> --region <REGION> --task <TASK_ID> --container <CONTAINER_NAME> --command "/bin/bash" --interactive