Uploading to S3 on the command line
throwing data into a bucket
- tags
- bash
- ruby
- s3
- spaces
- curl
Contents
I want to store data from a shell scripts on a S3 compatible bucket from with in a docker container.
I'm going to be doing this on digital ocean, but I assume that any API compatible service would work.
Setup spaces in digital ocean
I'm going to be using digital ocean for these tests, and I setup my bucket with the following terraform snippet.
|
|
Environment Variables
AWS_ACCESS_KEY_ID | spaces id |
AWS_SECRET_ACCESS_KEY | access key |
AWS_END_POINT | nyc3.digitaloceanspaces.com |
BUCKET_NAME | the bucket name |
Using ruby
We'll first look at how to make a simple script to upload a file using a self contained ruby script.
|
|
Using curl (failure)
This does not work because the signature style isn't apt.
|
|
Using curl part two
This uses a different signature style which works to digital ocean.
|
|
Debian aws cli tools
|
|
Then build with
|
|
Now run it, passing in the right environment variables:
|
|
Then to list the buckets:
|
|
And to copy a file over:
|
|
s3cmd
|
|
|
|
|
|
Then to copy over a file
|
|
s3cmd
has a lot more functionality other than copying, so if you are
looking for something more complex – like mirroring – it is worth
exploring.
References
- https://superuser.com/questions/279986/uploading-files-to-s3-account-from-linux-command-line
- https://gist.github.com/chrismdp/6c6b6c825b07f680e710
- https://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
- https://s3tools.org/s3cmd
- https://github.com/s3tools/s3cmd/issues/1018
- https://docs.digitalocean.com/products/spaces/resources/s3cmd/
- https://gist.github.com/vszakats/2917d28a951844ab80b1
Previously
Next