• Stars
    star
    111
  • Rank 314,510 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Library to mock the AWS SDK for Node.js

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);
    }
});