AWS – Send a file to S3 Bucket using CURL

# AWS S3 Credentials
S3_BUCKET="YOUR_S3_BUCKET_NAME"
S3_ACCESS_KEY="YOUR_ACCESS_KEY"
S3_SECRET_KEY="YOUR_SECRET_KEY"

FILE_NAME="test.tar.gz"

# SENDING

date="$(date +%Y%m%d)"
dateFormatted="$(date -R)"
relativePath="/${S3_BUCKET}/${FILE_NAME}"
contentType="application/octet-stream"
stringToSign="PUT\n\n${contentType}\n${dateFormatted}\n${relativePath}"
signature="$(echo -en ${stringToSign} | openssl sha1 -hmac ${S3_SECRET_KEY} -binary | base64)"
curl -X PUT -T "${FILE_NAME}" \
-H "Host: ${S3_BUCKET}.s3.amazonaws.com" \
-H "Date: ${dateFormatted}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${S3_ACCESS_KEY}:${signature}" \
http://${S3_BUCKET}.s3.amazonaws.com/${FILE_NAME}

 

Tagged: Tags

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments