Question
Creating a bucket using the AWS S3 Node Library
Hello everyone, I’m trying to create a new bucket on my space using the node AWS S3 API. It says on the official DO docs that CRUD operations are supported using the AWS S3 API. Here is the code I’m attempting to use:
const spacesEndpoint = new AWS.Endpoint('sfo2.digitaloceanspaces.com');
let connection = new AWS.S3({
endpoint: spacesEndpoint,
accessKeyId: SPACES_KEY,
secretAccessKey: SPACES_SEC
});
var bucketParams = {
Bucket : 'Test Bucket',
};
// call spaces to create the bucket
connection.createBucket(bucketParams, function(err, data) {
if (err) {
console.log("CANT CREATE BUCKET", err);
} else {
console.log(data);
}
});
However when attempting to do this I get the following error:
CANT CREATE BUCKET { InvalidRequest: Malformed request
at Request.extractError (/Users/.../api/node_modules/aws-sdk/lib/services/s3.js:585:35)
at Request.callListeners (/Users/.../api/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/Users/.../api/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/Users/j.../api/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/Users/.../api/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/Users/.../api/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /Users.../api/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request. (/Users/.../api/node_modules/aws-sdk/lib/request.js:38:9)
at Request. (/Users/.../api/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/Users/.../api/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
message: 'Malformed request',
code: 'InvalidRequest',
region: null,
time: 2019-03-08T06:38:42.054Z,
requestId: null,
extendedRequestId: undefined,
cfId: undefined,
statusCode: 400,
retryable: false,
retryDelay: 15.49543719310611 }
I can’t find any documentation about using this or creating a bucket with this API on your site, so I thought I’d open this ticket. I know the connection is good because I can use the upload endpoint to upload files, but can’t create buckets. Does anyone have any idea what’s going on here or what I’m missing?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×