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.
If you just make your
entrypointbe/bin/bashinstead ofentrypoint.shthen the task will start up and just sit there doing nothing forever until you kill it. Then you can perform anecs execinto the instance and do whatever you want.Alternatively, increase the
sleepnumber to a much higher value. For example, you could do something likesleep 1hto have it sit there for an hour.