Skip to content

Instantly share code, notes, and snippets.

@jclosure
Created January 25, 2024 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jclosure/4f6f25c607a4c91b1536be2cdc5c808a to your computer and use it in GitHub Desktop.
Save jclosure/4f6f25c607a4c91b1536be2cdc5c808a to your computer and use it in GitHub Desktop.
Download S3 objects with only curl
#!/bin/bash
# Example:
# for minio: in k9s, forward ports 9000 and 9001 to localhost
# ./curl_object_downloader.sh localhost:9000 mykey_id mykey_secret \
# mybucket mypath/myobj.bin ./myobj.bin
# User Minio Vars
URL=$1
USERNAME=$2
PASSWORD=$3
BUCKET=$4
MINIO_PATH="/${BUCKET}/$5"
OUT_FILE=$6
# Static Vars
DATE=$(date -R --utc)
CONTENT_TYPE='application/zstd'
SIG_STRING="GET\n\n${CONTENT_TYPE}\n${DATE}\n${MINIO_PATH}"
SIGNATURE=`echo -en ${SIG_STRING} | openssl sha1 -hmac ${PASSWORD} -binary | base64`
curl -o "${OUT_FILE}" \
-H "Host: $URL" \
-H "Date: ${DATE}" \
-H "Content-Type: ${CONTENT_TYPE}" \
-H "Authorization: AWS ${USERNAME}:${SIGNATURE}" \
http://$URL${MINIO_PATH}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment