Skip to content

Commit 6f79ddc

Browse files
authored
support assumed roles and users (#177)
1 parent 0886cdf commit 6f79ddc

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

worker/run-worker.sh

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
echo "${BASH_VERSION}"
33
echo "Region $AWS_REGION"
44
echo "Queue $SQS_QUEUE_URL"
5-
if [[ -z "$AWS_BUCKET" ]]
6-
then
5+
if [[ -z "$SOURCE_BUCKET" ]]; then
76
SOURCE_BUCKET=$AWS_BUCKET
87
fi
98
echo "Source Bucket $SOURCE_BUCKET"
109

10+
mkdir -p /home/ubuntu/bucket
11+
mkdir -p /home/ubuntu/local_output
12+
1113
# 1. CONFIGURE AWS CLI
14+
echo "Configuring AWS CLI"
1215
aws configure set default.region $AWS_REGION
1316
MY_INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
1417
echo "Instance ID $MY_INSTANCE_ID"
@@ -19,20 +22,24 @@ aws ec2 create-tags --resources $VOL_0_ID --tags Key=Name,Value=${APP_NAME}Worke
1922
VOL_1_ID=$(aws ec2 describe-instance-attribute --instance-id $MY_INSTANCE_ID --attribute blockDeviceMapping --output text --query BlockDeviceMappings[1].Ebs.[VolumeId])
2023
aws ec2 create-tags --resources $VOL_1_ID --tags Key=Name,Value=${APP_NAME}Worker
2124

22-
2325
# 2. MOUNT S3
24-
echo $AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY > /credentials.txt
25-
chmod 600 /credentials.txt
26-
mkdir -p /home/ubuntu/bucket
27-
mkdir -p /home/ubuntu/local_output
28-
stdbuf -o0 s3fs $AWS_BUCKET /home/ubuntu/bucket -o passwd_file=/credentials.txt
29-
26+
echo "Mounting S3 using S3FS"
27+
if [[ -z "$AWS_ACCESS_KEY_ID" ]]; then
28+
echo "Using role credentials to mount S3"
29+
s3fs $SOURCE_BUCKET /home/ubuntu/bucket -o iam_role
30+
else
31+
echo "Using user credentials to mount S3"
32+
echo $AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY > /credentials.txt
33+
chmod 600 /credentials.txt
34+
s3fs $SOURCE_BUCKET /home/ubuntu/bucket -o passwd_file=/credentials.txt
35+
fi
3036

3137
# 3. SET UP ALARMS
38+
echo "Setting up instance metric alarms"
3239
aws cloudwatch put-metric-alarm --alarm-name ${APP_NAME}_${MY_INSTANCE_ID} --alarm-actions arn:aws:swf:${AWS_REGION}:${OWNER_ID}:action/actions/AWS_EC2.InstanceId.Terminate/1.0 --statistic Maximum --period 60 --threshold 1 --comparison-operator LessThanThreshold --metric-name CPUUtilization --namespace AWS/EC2 --evaluation-periods 15 --dimensions "Name=InstanceId,Value=${MY_INSTANCE_ID}"
3340

3441
# 4. RUN VM STAT MONITOR
35-
42+
echo "Setting up instance monitor"
3643
python3.8 instance-monitor.py &
3744

3845
# 5. UPDATE AND/OR INSTALL PLUGINS
@@ -67,6 +74,7 @@ if [[ ${USE_PLUGINS} == 'True' ]]; then
6774
fi
6875

6976
# 6. RUN CP WORKERS
77+
echo "Starting workers"
7078
for((k=0; k<$DOCKER_CORES; k++)); do
7179
python3.8 cp-worker.py |& tee $k.out &
7280
sleep $SECONDS_TO_START

0 commit comments

Comments
 (0)