Skip to content

Instantly share code, notes, and snippets.

@prasanthj
Last active March 1, 2019 17:17
Show Gist options
  • Select an option

  • Save prasanthj/ede362218900ce49490bfd0ac5e5428c to your computer and use it in GitHub Desktop.

Select an option

Save prasanthj/ede362218900ce49490bfd0ac5e5428c to your computer and use it in GitHub Desktop.

Revisions

  1. prasanthj revised this gist Mar 1, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion s3-get-speed-private.sh
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ BUCKET=`echo $1 | cut -d '/' -f 4`
    KEY=`echo $1 | cut -d '/' -f 5- `
    REGION=`echo $1 | cut -d '-' -f 2-4 | cut -d '.' -f 1`
    CONTENT_TYPE="text/html; charset=UTF-8"
    DATE="`DATE -u +'%a, %d %b %Y %H:%M:%S GMT'`"
    DATE="`date -u +'%a, %d %b %Y %H:%M:%S GMT'`"
    RESOURCE="/${BUCKET}/${KEY}"
    SIG_INPUT="GET\n\n${CONTENT_TYPE}\n\nx-amz-date:${DATE}\n${RESOURCE}"
    SIGNATURE=`echo -en $SIG_INPUT | openssl sha1 -hmac "${AWS_SECRET_ACCESS_KEY}" -binary | base64`
  2. prasanthj created this gist Mar 1, 2019.
    38 changes: 38 additions & 0 deletions s3-get-speed-private.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #!/bin/bash
    set -e

    : ${AWS_ACCESS_KEY_ID:?"AWS_ACCESS_KEY_ID should be set in script or exported"}
    : ${AWS_SECRET_ACCESS_KEY:?"AWS_SECRET_ACCESS_KEY should be set in script or exported"}

    if [[ $# -eq 0 ]] ; then
    echo 'S3 object URL expected as argument. Usage: ./s3-get-speed-private.sh <s3-private-object-uri>'
    exit 0
    fi
    BUCKET=`echo $1 | cut -d '/' -f 4`
    KEY=`echo $1 | cut -d '/' -f 5- `
    REGION=`echo $1 | cut -d '-' -f 2-4 | cut -d '.' -f 1`
    CONTENT_TYPE="text/html; charset=UTF-8"
    DATE="`DATE -u +'%a, %d %b %Y %H:%M:%S GMT'`"
    RESOURCE="/${BUCKET}/${KEY}"
    SIG_INPUT="GET\n\n${CONTENT_TYPE}\n\nx-amz-date:${DATE}\n${RESOURCE}"
    SIGNATURE=`echo -en $SIG_INPUT | openssl sha1 -hmac "${AWS_SECRET_ACCESS_KEY}" -binary | base64`

    echo "Downloading to /dev/null.."
    CURL_STATS=`curl -w '%{speed_download}\t%{time_namelookup}\t%{time_connect}\t%{time_pretransfer}\t%{time_starttransfer}\t%{time_redirect}\t%{time_total}\n' -o /dev/null -H "x-amz-date: ${DATE}" -H "Content-Type: ${CONTENT_TYPE}" -H "Authorization: AWS ${AWS_ACCESS_KEY_ID}:${SIGNATURE}" -s $1`
    SPEED=`echo $CURL_STATS | awk '{print $1}' | sed 's/\..*//'`
    DNS_TIME=`echo $CURL_STATS | awk '{print $2}'`
    CONNECT_TIME=`echo $CURL_STATS | awk '{print $3}'`
    PRE_TRANSFER_TIME=`echo $CURL_STATS | awk '{print $4}'`
    START_TRANSFER_TIME=`echo $CURL_STATS | awk '{print $5}'`
    REDIRECT_TIME=`echo $CURL_STATS | awk '{print $6}'`
    TOTAL_TIME=`echo $CURL_STATS | awk '{print $7}'`
    MBSPEED=`awk -v s=$SPEED 'BEGIN { print s/(1024*1024) }'`

    echo "--- S3 GET STATS ---"
    echo "namelookup: ${DNS_TIME}s"
    echo "connect: ${CONNECT_TIME}s"
    echo "pre-transfer: ${PRE_TRANSFER_TIME}s"
    echo "start-transfer: ${START_TRANSFER_TIME}s"
    echo "redirect: ${REDIRECT_TIME}s"
    echo "total: ${TOTAL_TIME}s"
    echo "speed: ${MBSPEED}MB/s"