Skip to content

Commit

Permalink
Allow the setting of instance is for file download
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjw1 committed Jan 26, 2024
1 parent bef9609 commit 507fb56
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bin/ecs/file-download
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ usage() {
echo "Usage: $(basename "$0") [OPTIONS]" 1>&2
echo " -h - help"
echo " -i <infrastructure> - infrastructure name"
echo " -I <instance> - instance id"
echo " -e <environment> - environment name (e.g. 'staging' or 'prod')"
echo " -s <source> - Source"
echo " -t <local target> - local target"
Expand All @@ -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
;;
Expand Down Expand Up @@ -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" \
Expand Down

0 comments on commit 507fb56

Please sign in to comment.