Uploading and downloading documents from Amazon S3 using bash

You need to upload a file to S3 and cannot install new packages in the server, nor the s3 client tools. You only have bash, openssl and sed. Go.

I found and adapted a script by Viktor Szakats, that creates all the proper headers expected by the latest AWS API. I had lots of trouble with whitespaces and empty lines. Be mindful of that when modifying these scripts:

s3-upload-aws4.sh

s3-download-aws4.sh

run them like:


. s3-upload-aws4.sh "myfile.ext" "my_bucket_name" "folder_name_in_bucket" "region" "REDUCED_REDUNDANCY" "MY_AWS_ACCESS_KEY" "MY_AWS_SECRET_KEY"

 

I'm a software architect and I help people solve their problems with technology. In this site, I write about how to seize the opportunities that a hyperconnected world offers us. How to live simpler and more productive lives. I invite you to check the "Best of" section. If you want to contact me, or work with me, you can use the social links below.