Skip to content

Instantly share code, notes, and snippets.

@krasnuydyx
Last active November 22, 2017 14:00
Show Gist options
  • Save krasnuydyx/81206cad224207bb7245908815a75385 to your computer and use it in GitHub Desktop.
Save krasnuydyx/81206cad224207bb7245908815a75385 to your computer and use it in GitHub Desktop.
AWS S3 console upload/download/delete
S3KEY=""
BUCKET=""
REGION="s3"
S3SECRET=""
file=$1
resource="/${BUCKET}/${file}"
contentType="application/x-compressed-tar"
dateValue=`date -R`
stringToSign="DELETE\n\n${contentType}\n${dateValue}\n${resource}"
echo "DELETING FROM S3"
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${S3SECRET} -binary | base64`
curl -X DELETE \
-H "Host: ${BUCKET}.${REGION}.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${S3KEY}:${signature}" \
https://${BUCKET}.${REGION}.amazonaws.com/${file}
S3KEY=""
BUCKET=""
REGION="s3"
S3SECRET=""
file=$1
resource="/${BUCKET}/${file}"
contentType="application/x-compressed-tar"
dateValue=`date -R`
stringToSign="GET\n\n${contentType}\n${dateValue}\n${resource}"
echo "DOWNLOADING FROM S3"
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${S3SECRET} -binary | base64`
curl -o ${file} \
-H "Host: ${BUCKET}.${REGION}.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${S3KEY}:${signature}" \
https://${BUCKET}.${REGION}.amazonaws.com/${file}
S3KEY=""
BUCKET=""
REGION="s3"
S3SECRET=""
file=$1
resource="/${BUCKET}/${file}"
contentType="application/x-compressed-tar"
dateValue=`date -R`
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
echo "SENDING TO S3"
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${S3SECRET} -binary | base64`
curl -X PUT -T "${file}" \
-H "Host: ${BUCKET}.${REGION}.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${S3KEY}:${signature}" \
https://${BUCKET}.${REGION}.amazonaws.com/${file}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment