forked from jean553/docker-s3-server-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_bucket.js
More file actions
38 lines (33 loc) · 1.07 KB
/
create_bucket.js
File metadata and controls
38 lines (33 loc) · 1.07 KB
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
// Create a new bucket inside the local s3,
// if a bucket name is specified in the environment
var AWS = require('aws-sdk');
var endpoint = new AWS.Endpoint('http://0.0.0.0:5000');
// Set some dummy credentials
var credentials = new AWS.Credentials(
{
accessKeyId : 'dummy_value_cannot_be_none',
secretAccessKey : 'dummy_value_cannot_be_none'
}
);
// Create an S3 client
var s3 = new AWS.S3(
{
endpoint : endpoint,
credentials : credentials,
s3ForcePathStyle: true // Force client to look for hostname/my_bucket instead of my_bucket.hostname
}
);
// Get the bucket name from the environment
var bucket_name = process.env.S3_BUCKET_NAME;
if (bucket_name && bucket_name != null)
s3.createBucket(
{Bucket : bucket_name},
function(error, success) {
if (success && success != null) {
console.log("Bucket " + bucket_name + " created");
}
else {
console.log("Can't create bucket " + bucket_name + ": " + error.code);
}
}
);