Creating a bucket using the AWS S3 Node Library

Posted March 11, 2019 3.1k views

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('');

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 {

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.

Submit an Answer
1 answer

Hey friend,

I’m not an expert on node myself, so it may be possible that someone can come in behind me and offer a more complete answer. However, I do love me some Python and so I just used the sample script here to create a bucket and verify that the API is functioning before digging further:

All went well there, so I started looking at the two code samples here (mine and yours), and then this part of your output stood out to me after I noticed a difference:

region: null,

I do not know about the capabilities of the library being used here, but it looks like our system does require the region name to be sent in addition to the region-specific end point. Perhaps if that can be reconciled, this might work?

Also in your sample you have a space in the bucket name, and that may just be for pasting it here, but make sure that you don’t have one in there when you run the code.