Mock AWS S3 SDK
This is a very simple interface that mocks the AWS SDK for Node.js. The implementation is incomplete but most basic features are supported.
Available:
- createBucket
- deleteBucket
- listObjects
- listObjectsV2
- deleteObjects
- deleteObject
- getObject
- headObject
- putObject
- copyObject
- getObjectTagging
- putObjectTagging
- upload
- getSignedUrl
It uses a directory to mock a bucket and its content.
If you'd like to see some more features or you have some suggestions, feel free to use the issues or submit a pull request.
Release History
- 2021-04-10โโโv4.0.2โโโUpdate dependencies, remove extra log and use proper path concat
- 2020-01-30โโโv4.0.0โโโFix promises and update packages with various contributions.
- 2018-06-16โโโv3.0.0โโโContributions from @benedict-wellard and @telenor-digital-asia adding support for promises and deleteBucket
- 2017-08-11โโโv2.6.0โโโContributions from @pamelafox and @fkleon adding support for listObjectsV2, tagging and more useful debug info returned
- 2017-05-31โโโv2.5.1โโโFix bug when statSync was called on non existing files, spotted by @AllanHodkinson
- 2017-05-20โโโv2.5.0โโโSet LastModified on getObject by @stujo, support for custom metadata on get/head by @rgparkins and putObject returns some data on error by @pamelafox
- 2017-02-02โโโv2.4.0โโโAccount for no existing keys when getting an object by @derPuntigamer
- 2016-06-03โโโv2.3.0โโโAdd createBucket method and tests by @neilstuartcraig
- 2016-05-25โโโv2.2.1โโโAdd Size attribute by @aldafu
- 2016-04-25โโโv2.2.0โโโAdd MaxKey options in listObject by @hauboldj
- 2016-01-18โโโv2.1.0โโโFix markers on listObjects (by @wellsjo) and add send method (by @AllieRays and @IonicaBizau)
- 2015-11-04โโโv2.0.0โโโStatic basePath configuration, bound params (by @CJNE) and match upload API (by @kyleseely)
- 2015-10-25โโโv1.1.0โโโRemoved because of potential breaking change with bound params
- 2015-09-24โโโv1.0.0โโโBreaking changes and awesome PR to fix API inconsistencies by @irothschild
- 2015-08-27โโโv0.5.0โโโRefactor and default options by @whitingj
- 2015-07-28โโโv0.4.0โโโAdd headObject method by @mdlavin
- 2015-07-21โโโv0.3.0โโโAdd CommonPrefixes to listObjects by @jakepruitt
- 2015-03-15โโโv0.2.7โโโMock out AWS' config submodule by @necaris
- 2015-03-13โโโv0.2.6โโโPartial match support and ContentLength by @mick
- 2015-03-03โโโv0.2.5โโโAllow string and fix tests by @lbud
- 2015-02-05โโโv0.2.4โโโFix url encoding for copy by @ahageali
- 2015-01-22โโโv0.2.3โโโSupport for copyObject
- 2014-02-02โโโv0.2.1โโโSupport for deleteObject
- 2014-01-08โโโv0.2.0โโโSupport streams for getObject/putObject
- 2013-10-24โโโv0.1.2โโโFix isTruncated typo
- 2013-10-09โโโv0.1.1โโโAdd LastModified to listObject
- 2013-08-09โโโv0.1.0โโโFirst release
Example
Instantiate
var AWSMock = require('mock-aws-s3');
AWSMock.config.basePath = '/tmp/buckets/' // Can configure a basePath for your local buckets
var s3 = AWSMock.S3({
params: { Bucket: 'example' }
});
PutObject/ListObjects
s3.putObject({Key: 'sea/animal.json', Body: '{"is dog":false,"name":"otter","stringified object?":true}'}, function(err, data) {
s3.listObjects({Prefix: 'sea'}, function (err, data) {
console.log(data);
});
});
CreateBucket
var params = { Bucket: 'example' };
s3.createBucket(params, function(err) {
if(err) {
console.error(err);
}
});
DeleteBucket
var params = { Bucket: 'example' };
s3.deleteBucket(params, function(err) {
if(err) {
console.error(err);
}
});