Developing Amazon S3 locally using fakes3
We can use fake S3 to simulate Amazon S3 service locally.
Installation
Use gem to install fakes3
gem install fakes3
Then you can start the fakes3 server
fakes3 --root=/var/tmp/fakes3 --port=10453
that will open port at 10453 and store data at /var/tmp/fakes3
Editing /etc/hosts
To redirect traffic back to localhost, add the following line:
127.0.0.1 fakes3.local testme.waterworld.com.hk.fakes3.local
that testme.waterworld.com.hk will be the bucket name that we will use later.
Knox
Testing if fakes3 works, we build some code using knox
knox=require('knox')
client=knox.createClient
key: "hello"
secret: "world"
bucket: "testme.waterworld.com.hk"
endpoint: "fakes3.local"
secure: false
port: 10453
string = "hello world"
req = client.put '/test/a.txt',
'Content-Length': string.length
'Content-Type': 'application/json'
req.on 'response', (res) ->
console.log "saved #{req.url}, #{res.statusCode}"
req.end(string)
Noted that will must disable secure, set the port and endpoint.
run it:
> coffee test.coffee
saved http://testme.waterworld.com.hk.fakes3.local:10453/test/a.txt, 200
At the server, it should log:
localhost - - [10/Apr/2014:18:41:15 HKT] "PUT /test/a.txt HTTP/1.1" 200 0
- -> /test/a.txt
Also you should able to find your data stored at /var/tmp/fakes3 folder.