-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_fargate_task.sh
executable file
·32 lines (23 loc) · 1.2 KB
/
run_fargate_task.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
#!/bin/bash
STACK_NAME=$1
REGION=$2
SUBNETS=$3
CLUSTER_NAME=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --region $REGION --query 'Stacks[0].Outputs[?OutputKey==`ClusterName`].OutputValue' --out text)
TASK_DEFINITION=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --region $REGION --query 'Stacks[0].Outputs[?OutputKey==`TaskDefinitionName`].OutputValue' --out text)
NETWORK_CONF="awsvpcConfiguration={subnets=[$SUBNETS],assignPublicIp='ENABLED'}"
run_new_task(){
local TASK_ARN=$(aws ecs run-task --cluster $CLUSTER_NAME --task-definition $TASK_DEFINITION --count 1 --network-configuration $NETWORK_CONF --launch-type FARGATE --region $REGION --query 'tasks[0].taskArn' --out text)
echo "$TASK_ARN"
}
get_return_Code () {
local RETURN_CODE=$(aws ecs describe-tasks --tasks $TASK_ARN --cluster $CLUSTER_NAME --region $REGION --query 'tasks[0].containers[0].exitCode' --out text)
echo "$RETURN_CODE"
}
echo "Running a new Fragate Task task"
TASK_ARN=$(run_new_task)
echo "Waiting until the container finishes running the script"
sleep 60
echo "Checking the Return Code of the job"
RETURN_CODE=$(get_return_Code)
echo "Return Code: $RETURN_CODE \n"
echo "Checking the logs of the job"