-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathputTestObjects.js
61 lines (56 loc) · 1.65 KB
/
putTestObjects.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const async = require('async');
const AWS = require('aws-sdk');
AWS.config.update({
accessKeyId: "accessKey1",
secretAccessKey: "verySecretKey1",
region: "us-west-1",
sslEnabled: false,
endpoint:'http://127.0.0.1:8000',
s3ForcePathStyle: true,
apiVersions: { s3: '2006-03-01' },
signatureVersion: 'v4',
signatureCache: false,
maxRetries: 0,
});
const s3 = new AWS.S3({
httpOptions: { maxRetries: 0, timeout: 0 },
});
// configurable params
const BUCKET = 'foo';
const LISTING_LIMIT = 10;
const OBJECT_TOTAL = 20000;
const VERSIONS_TOTAL = 100;
const ASYNC_LIMIT = 10;
function _putObjectVersions(num, count, cb) {
async.timesLimit(
count, 2,
(n, next) => s3.putObject({Bucket: BUCKET, Key: 'key-' + num, Body: 'foo' }, next),
cb
);
}
s3.createBucket({ Bucket: BUCKET }, err => {
if (err && err.code !== 'BucketAlreadyOwnedByYou') {
console.log('error creating bucket', err);
return;
}
console.log('created bucket', BUCKET);
s3.putBucketVersioning({
Bucket: BUCKET,
VersioningConfiguration: {
Status: "Enabled"
},
}, err => {
if (err) {
console.log('error putting versioning on bucket', err);
return
}
console.log('put versioning on bucket', BUCKET);
async.timesLimit(OBJECT_TOTAL, ASYNC_LIMIT, (n, next) =>
_putObjectVersions(n, VERSIONS_TOTAL, next), (err, res) => {
if (err) {
return console.log('error occured', err);
}
return console.log('successfully put objects');
});
});
});