Running commands inside ECS containers2 - alphagov/notifications-manuals GitHub Wiki

Introduction to ecs containers

Notify App runs on containers deployed on AWS ECS. These are serverless containers running in ecs clusters like this:

https://eu-west-1.console.aws.amazon.com/ecs/v2/clusters/notify/services?region=eu-west-1

Running commands inside containers

Sometimes it is necessary/desired to go into a running container for debugging purpose.

To run commands directly inside a container, it must be configured to accept such connections.

you can connect to your container by running the following command:

gds aws <aws-environment> \
-- aws ecs execute-command \
--cluster <cluster-name> \
--task <task-id> \
--container <container-name> \
--interactive \
--command "/bin/sh"

Hopefully you will get connected to the container

Screenshot 2023-04-04 at 11 21 23

Troubleshooting

If you cannot get connected a good first step is to analyse if the setup in your machine and the container is done

1. Verify if ECS Exec is enabled on an ECS task

There is a useful tool called Amazon ECS Exec Checker that allows you to check and validate if your ECS service/task is already able to run ECS Exec

Screenshot 2023-04-03 at 17 37 03

2. Check you have session manager plugin installed

$ session-manager-plugin
The Session Manager plugin was installed successfully. Use the AWS CLI to start a session.
⚠️ **GitHub.com Fallback** ⚠️