-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtask_shell.sh
executable file
·60 lines (44 loc) · 1.73 KB
/
task_shell.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# Enable strict mode
set -euo pipefail
# Uncomment for debug
# set -x
# Set AWS profile and function name
export AWS_PROFILE=cdl-pad-dev
export FUNC=pub-dspace-dev
# Function to display script usage
show_usage() {
echo "Usage: $0 <service_component> e.g. backend, frontend, solr"
echo "Example: $0 backend"
echo "NOTE: you must have configured the appropriate IAM role"
echo "and permissions for the container, and the container"
echo "needs the execute command flag set."
echo
exit 1
}
# Check if no service/task name is provided or too many parameters are given
if test "$#" -ne 1; then
show_usage
fi
# Check if '-h' or '--help' is provided as an argument
if [[ "$1" == '-h' || "$1" == '--help' ]]; then
show_usage
fi
# Get the service/task name from the command line
SERVICE_NAME=$1
# Build container name
CONTAINER_NAME="dspace-${1}"
# Build the service family based on the provided function and service name
SERVICE_FAMILY="${FUNC}-${SERVICE_NAME}"
# Get the task ARN based on the specified service family
TASK_ARN=$(aws ecs list-tasks --cluster ${FUNC}-cluster --family ${SERVICE_FAMILY} --query "taskArns[0]" --output text)
if [ -z "$TASK_ARN" ]; then
echo "No running task found for service family: $SERVICE_FAMILY"
exit 1
fi
echo "Task: $TASK_ARN"
# known working command: aws ecs execute-command --task arn:aws:ecs:us-west-2:866216109762:task/pub-dspace-dev-cluster/db89a0a7acaa4f8f9472df53bc81b66d --cluster pub-dspace-dev-cluster --container dspace-backend --command /bin/bash --interactive
# Execute command to shell into the specified task
aws ecs execute-command --cluster ${FUNC}-cluster --task $TASK_ARN \
--container ${CONTAINER_NAME} --command "/bin/bash" --interactive
exit 0