0

I need to be able to spin up a shell in a task to take a look at my production database, but the task keeps dying. I need it to stay alive as long as I am using it + 10 minutes.

I have a service and task definition. I create the task and get the task arn like this:

TASK_ARN=$(aws ecs run-task --query "tasks[0].taskArn" --output text --enable-execute-command --cluster $CLUSTER_NAME --task-definition $TASK_DEFINITION_NAME --launch-type FARGATE --count 1

I connect to the task like this:

aws ecs execute-command --region $REGION --cluster $CLUSTER_NAME --task $TASK_ARN --container $CONTAINER_NAME --command "python manage.py shell_plus" --interactive

The task definition has an entrypoint.sh, and inside the entrypoint.sh I have this.

#!/bin/bash
sleep 60

The 60 seconds is enough to connect to the task, but once I'm connected it dies after the sleep is finished.

What can I add into my entrypoint.sh to make it stay alive as long as I'm connected to it? Ideally it stays alive for at 10 minutes without any activity and then dies.

Cedric Holz
  • 51
  • 1
  • 4

1 Answers1

0

If you just make your entrypoint be /bin/bash instead of entrypoint.sh then the task will start up and just sit there doing nothing forever until you kill it. Then you can perform an ecs exec into the instance and do whatever you want.

Alternatively, increase the sleep number to a much higher value. For example, you could do something like sleep 1h to have it sit there for an hour.

Mark B
  • 183,023
  • 24
  • 297
  • 295