S3rver is a lightweight server that responds to some of the same calls Amazon S3 responds to. It is extremely useful for testing S3 in a sandbox environment without actually making calls to Amazon.
The goal of S3rver is to minimise runtime dependencies and be more of a development tool to test S3 calls in your code rather than a production server looking to duplicate S3 functionality.
- Create bucket
- Delete bucket
- List buckets
- List content of buckets (prefix, delimiter, marker and max keys, common prefixes)
- Put object (support for metadata, including ContentEncoding (gzipped files)
- Delete object(s)
- Get object (including using the HEAD method)
- Get dummy ACLs for an object
- Copy object (including updating of metadata)
Install s3rver:
npm install s3rver -g
You will now have a command on your path called s3rver
Executing this command for the various options:
s3rver --help
Please see Fake S3s wiki page for a list of supported clients.
When listening on HTTPS with a self-signed certificate, the AWS SDK in a Node.js environment will need httpOptions: { agent: new https.Agent({ rejectUnauthorized: false }) }
in order to allow interaction.
Please test, if you encounter any problems please do not hesitate to open an issue :)
If you specify an indexDocument then get
requests will serve the indexDocument if it is found, simulating the static website mode of AWS S3. An errorDocument can also be set, to serve a custom 404 page.
By default a bucket name needs to be given. So for a bucket called mysite.local
, with an indexDocument of index.html
. Visiting http://localhost:4568/mysite.local/
in your browser will display the index.html
file uploaded to the bucket.
However you can also setup a local hostname in your /etc/hosts file pointing at 127.0.0.1
localhost 127.0.0.1
mysite.local 127.0.0.1
Now you can access the served content at http://mysite.local:4568/
The tests should be run by one of the active LTS versions. The CI Server runs the tests on version 4.x
, 6.x
and 8.x
.
I recommend using NVM to manage your node versions.
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test
You can also run s3rver programmatically.
This is particularly useful if you want to integrate s3rver into another projects tests that depends on access to an s3 environment
Example in mocha:
var S3rver = require('s3rver');
var client;
before(function (done) {
client = new S3rver({
port: 4569,
hostname: 'localhost',
silent: false,
directory: '/tmp/s3rver_test_directory'
}).run(function (err, host, port) {
if(err) {
return done(err);
}
done();
});
});
after(function (done) {
client.close(done);
});
Using s3fs-fuse with S3rver
You can connect to s3rver and mount a bucket to your local file system by using the following command:
s3fs bucket1 /tmp/3 -o url="http://localhost:4568" -o use_path_request_style -d -f -o f2 -o curldbg