UNPKG

3.7 kBMarkdownView Raw
1# Mock AWS S3 SDK
2
3This is a very simple interface that mocks the AWS SDK for Node.js. The implementation is incomplete but most basic features are supported.
4
5Available:
6- createBucket
7- deleteBucket
8- listObjects
9- listObjectsV2
10- deleteObjects
11- deleteObject
12- getObject
13- headObject
14- putObject
15- copyObject
16- getObjectTagging
17- putObjectTagging
18- upload
19- getSignedUrl
20
21It uses a directory to mock a bucket and its content.
22
23If you'd like to see some more features or you have some suggestions, feel free to use the issues or submit a pull request.
24
25## Release History
26* 2018-06-16   v3.0.0   Contributions from @benedict-wellard and @telenor-digital-asia adding support for promises and deleteBucket
27* 2017-08-11   v2.6.0   Contributions from @pamelafox and @fkleon adding support for listObjectsV2, tagging and more useful debug info returned
28* 2017-05-31   v2.5.1   Fix bug when statSync was called on non existing files, spotted by @AllanHodkinson
29* 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
30* 2017-02-02   v2.4.0   Account for no existing keys when getting an object by @derPuntigamer
31* 2016-06-03   v2.3.0   Add createBucket method and tests by @neilstuartcraig
32* 2016-05-25   v2.2.1   Add Size attribute by @aldafu
33* 2016-04-25   v2.2.0   Add MaxKey options in listObject by @hauboldj
34* 2016-01-18   v2.1.0   Fix markers on listObjects (by @wellsjo) and add send method (by @AllieRays and @IonicaBizau)
35* 2015-11-04   v2.0.0   Static basePath configuration, bound params (by @CJNE) and match upload API (by @kyleseely)
36* 2015-10-25   v1.1.0   Removed because of potential breaking change with bound params
37* 2015-09-24   v1.0.0   Breaking changes and awesome PR to fix API inconsistencies by @irothschild
38* 2015-08-27   v0.5.0   Refactor and default options by @whitingj
39* 2015-07-28   v0.4.0   Add headObject method by @mdlavin
40* 2015-07-21   v0.3.0   Add CommonPrefixes to listObjects by @jakepruitt
41* 2015-03-15   v0.2.7   Mock out AWS' config submodule by @necaris
42* 2015-03-13   v0.2.6   Partial match support and ContentLength by @mick
43* 2015-03-03   v0.2.5   Allow string and fix tests by @lbud
44* 2015-02-05   v0.2.4   Fix url encoding for copy by @ahageali
45* 2015-01-22   v0.2.3   Support for copyObject
46* 2014-02-02   v0.2.1   Support for deleteObject
47* 2014-01-08   v0.2.0   Support streams for getObject/putObject
48* 2013-10-24   v0.1.2   Fix isTruncated typo
49* 2013-10-09   v0.1.1   Add LastModified to listObject
50* 2013-08-09   v0.1.0   First release
51
52## Example
53
54### Instantiate
55
56```js
57var AWSMock = require('mock-aws-s3');
58AWSMock.config.basePath = '/tmp/buckets/' // Can configure a basePath for your local buckets
59var s3 = AWSMock.S3({
60 params: { Bucket: 'example' }
61});
62```
63
64### PutObject/ListObjects
65
66```js
67s3.putObject({Key: 'sea/animal.json', Body: '{"is dog":false,"name":"otter","stringified object?":true}'}, function(err, data) {
68 s3.listObjects({Prefix: 'sea'}, function (err, data) {
69 console.log(data);
70 });
71});
72```
73
74### CreateBucket
75
76```js
77var params = { Bucket: 'example' };
78s3.createBucket(params, function(err) {
79 if(err) {
80 console.error(err);
81 }
82});
83```
84
85### DeleteBucket
86
87```js
88var params = { Bucket: 'example' };
89s3.deleteBucket(params, function(err) {
90 if(err) {
91 console.error(err);
92 }
93});
94```