Create your own server AWS S3 open source

Amazon S3 (Simple Storage Service, simple storage service) is a very powerful online file storage service provided by Amazon Web Services. Think of it as a remote drive where you can store files in directories, get and delete them. Companies such as DropBox, Netflix, Pinterest, Slideshare, Tumblr and many others rely on him.
Though choice, his code is not open, so you have to trust Amazon with their data, and although they provide access to a free instance for a year, you still need to enter credit card information to create an account. Since S3 must know every software engineer, I want my students gained experience with it and used it in my web applications, and I don't want them to pay for it. Some students also work during the trips, meaning slow Internet connection and expensive traffic, or even complete absence of the Internet.
That's why I started looking for open solutions that would be emulated S3 API, which could work on any machine. As usual, the world of Open Source didn't disappoint me and provided several solutions, here's my favorite:
the
- Second option HP Helion Eucalyptus, which provides a wide range of emulation AWS (CloudFormation, Cloudwatch, ELB...), including support for S3. This is a very complete solution (only running on CentOS), focused on the enterprise and, unfortunately, too heavy for personal use or for your small business.
the - Last and my favorite option is server Scality S3. Available as a Docker image, which is very easy to unwrap and start using. The software is suitable for personal use, everyone can start using it after a few seconds without any complicated installation. But it is also suitable for the enterprise, because it is scalable and ready for production. The best of both worlds.
the First thing I came across was Fake S3 written in Ruby and available as a gem, it only takes a few seconds to install and the library is very well maintained. It's a great tool to start but it does not implement all the commands S3 and is not suitable for use in production.
the
the
getting started with server Scality S3
To demonstrate how easy it is to emulate AWS S3, server S3 Scality, let's revive it!
Requirements:
the
Run the Docker container server Scality S3:
the
$ docker run-d --name s3server -p 8000:8000 scality/s3server
Unable to find image 'scality/s3server:latest' locally
latest: Pulling from scality/s3server
357ea8c3d80b: Pull complete
52befadefd24: Pull complete
3c0732d5313c: Pull complete
ceb711c7e301: Pull complete
868b1d0e2aad: Pull complete
3a438db159a5: Pull complete
38d1470647f9: Pull complete
4d005fb96ed5: Pull complete
a385ffd009d5: Pull complete
Digest: sha256:4fe4e10cdb88da8d3c57e2f674114423ce4fbc57755dc4490d72bc23fe27409e
Status: Downloaded newer image for scality/s3server:latest
7c61434e5223d614a0739aaa61edf21763354592ba3cc5267946e9995902dc18
$
Make sure the Docker container is working properly:
the
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ed54e677b1b3 scality/s3server "npm start" 5 days ago Up 5 days 0.0.0.0:8000- > 8000/tcp s3server
Install the Ruby gem AWS SDK v2 (documentation here):
the
$ gem install aws-sdk
Now let's create the file that we will upload in our basket:
the
$ touch myfavoritefile
Using your favorite text editor, create a file containing your Ruby script, let's call it ‘s3_script.rb’:
the
#!/usr/bin/ruby
require 'aws-sdk'
s3 = Aws::S3::Client.new(
:access_key_id => 'accessKey1',
:secret_access_key => 'verySecretKey1',
:region = > 'us-west-2',
:endpoint => 'http://0.0.0.0:8000/',
:force_path_style => true
s3.create_bucket({bucket: "mybucket"})
File.open('myfavoritefile', 'rb') do |file|
s3.put_object(bucket: 'mybucket', key: 'myfavoritefile', body: file)
end
resp = s3.list_objects_v2(bucket: 'mybucket')
puts resp.contents.map (&: key)
Run the script:
the
$ ruby s3_script.rb
$ myfavoritefile
Congratulations, you have created your first S3-a basket and loaded the file!
the
Let's look at the code
Here, we specify that the script should be executed Ruby and that we are connected library AWS SDK:
the
#!/usr/bin/ruby
require 'aws-sdk'
We are initiating the connection to our S3 server running in our Docker container. Note that ‘accessKey1’ and ‘verySecretKey1’ is the access key and secret key to access the default server Scality S3:
the
s3 = Aws::S3::Client.new(
:access_key_id => 'accessKey1',
:secret_access_key => 'verySecretKey1',
:region = > 'us-west-2',
:endpoint => 'http://127.0.0.1:8000/',
:force_path_style => true
)
Create a S3-a basket called ‘mybucket’:
the
s3.create_bucket({bucket: "mybucket"})
Here we load our cart ‘mybucket’ file you created earlier ‘myfavoritefile’:
the
File.open('myfavoritefile', 'rb') do |file|
s3.put_object(bucket: 'mybucket', key: 'myfavoritefile', body: file)
end
Finally, collect the contents of the basket ‘mybucket’ and display it to standard output:
the
resp = s3.list_objects_v2(bucket: “mybucket”)
puts resp.contents.map (&: key)
Комментарии
Отправить комментарий