From 507fb566bac8d07f9f1e543f46d75493c417abdb Mon Sep 17 00:00:00 2001 From: bob walker Date: Fri, 26 Jan 2024 15:51:45 +0000 Subject: [PATCH] Allow the setting of instance is for file download If set override picking the first instance in the list this can be useful if there is more than one cluster in the environment or you are working on a specific instance. --- bin/ecs/file-download | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/ecs/file-download b/bin/ecs/file-download index ba8bb2b..62f6dba 100755 --- a/bin/ecs/file-download +++ b/bin/ecs/file-download @@ -11,6 +11,7 @@ usage() { echo "Usage: $(basename "$0") [OPTIONS]" 1>&2 echo " -h - help" echo " -i - infrastructure name" + echo " -I - instance id" echo " -e - environment name (e.g. 'staging' or 'prod')" echo " -s - Source" echo " -t - local target" @@ -35,11 +36,14 @@ fi RECURSIVE=0 -while getopts "i:e:s:t:rh" opt; do +while getopts "i:I:e:s:t:rh" opt; do case $opt in i) INFRASTRUCTURE_NAME=$OPTARG ;; + I) + INSTANCE_ID=$OPTARG + ;; e) ENVIRONMENT=$OPTARG ;; @@ -91,12 +95,11 @@ fi echo "==> Finding ECS instance..." INSTANCES=$(aws ec2 describe-instances --filters Name=instance-state-code,Values=16 Name=tag:Name,Values="$INFRASTRUCTURE_NAME-$ENVIRONMENT*") -INSTANCE_ID=$(echo "$INSTANCES" | jq -r '.Reservations[0].Instances[0].InstanceId' ) +INSTANCE_ID=${INSTANCE_ID:-$(echo "$INSTANCES" | jq -r '.Reservations[0].Instances[0].InstanceId' )} INSTANCE_NAME=$(echo "$INSTANCES" | jq -r '.Reservations[0].Instances[0].Tags[] | select(.Key == "Name") | .Value') echo "==> uploading from '$INSTANCE_NAME' (id: $INSTANCE_ID) to S3.." - aws ssm start-session \ --target "$INSTANCE_ID" \ --document-name "$INFRASTRUCTURE_NAME-$ENVIRONMENT-s3-upload" \