Report this

What is the reason for this report?

Issue completing basic commands for Spaces using s3 AWS SDK on NodeJS

Posted on July 27, 2020

Using the docs here, I attempted to get a list of available spaces. However, I get the following error:

NotImplemented: Server does not support one or more requested headers. Please see https://de
velopers.digitalocean.com/documentation/spaces/#aws-s3-compatibility                       
    at Request.extractError (/home/vincent/workspace/tuts-express-js/node_modules/aws-sdk/li
b/services/s3.js:837:35)                                                                   
    at Request.callListeners (/home/vincent/workspace/tuts-express-js/node_modules/aws-sdk/l
ib/sequential_executor.js:106:20)                                                          
    at Request.emit (/home/vincent/workspace/tuts-express-js/node_modules/aws-sdk/lib/sequen
tial_executor.js:78:10)                                                                    
    at Request.emit (/home/vincent/workspace/tuts-express-js/node_modules/aws-sdk/lib/reques
t.js:688:14)                                                                               
    at Request.transition (/home/vincent/workspace/tuts-express-js/node_modules/aws-sdk/lib/
request.js:22:10)                                                                          
    at AcceptorStateMachine.runTo (/home/vincent/workspace/tuts-express-js/node_modules/aws-
sdk/lib/state_machine.js:14:12)                                                            
    at /home/vincent/workspace/tuts-express-js/node_modules/aws-sdk/lib/state_machine.js:26:
10                                                                                         
    at Request.<anonymous> (/home/vincent/workspace/tuts-express-js/node_modules/aws-sdk/lib
/request.js:38:9)                                                                          
    at Request.<anonymous> (/home/vincent/workspace/tuts-express-js/node_modules/aws-sdk/lib
/request.js:690:12)                                                                        
    at Request.callListeners (/home/vincent/workspace/tuts-express-js/node_modules/aws-sdk/l
ib/sequential_executor.js:116:18) {                                                        
  code: 'NotImplemented',
  region: null,
  time: 2020-07-27T15:42:27.398Z,
  requestId: null,
  extendedRequestId: undefined,
  cfId: undefined,
  statusCode: 501,
  retryable: true

Code is below:

const AWS = require("aws-sdk");

// set to use the digital ocean s3
AWS.config.credentials = new AWS.SharedIniFileCredentials({
  profile: "digitalocean"
});

// configure endpoints for DO spaces
const spacesEndpoint = new AWS.Endpoint("nyc3.digitaloceanspaces.com");
const s3 = new AWS.S3({
  endpoint: spacesEndpoint
});

// list buckets
s3.listBuckets({}, function(err, data) {
  if (err) console.log(err, err.stack);
  else {
    data["Buckets"].forEach(function(space) {
      console.log(space["Name"]);
    });
  }
});

// list the available buckets
s3.listObjects({ Bucket: "my-experimental-expressjs-piece" }, function(
  err,
  data
) {
  if (err) {
    console.log(err);
  } else {
    console.log(data);
  }
});

Any idea what might be going wrong?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Hi there,

To list all buckets, you should use listBucketsCommand instead of listBuckets.

Here is an example on how to do that:

// Imports your configured client and any necessary S3 commands.
import { ListBucketsCommand } from "@aws-sdk/client-s3";
import { s3Client } from "./path/to/s3Client.js";

// Returns a list of Spaces in your region.
export const run = async () => {
  try {
    const data = await s3Client.send(new ListBucketsCommand({}));
    console.log("Success", data.Buckets);
    return data; // For unit tests.
  } catch (err) {
    console.log("Error", err);
  }
};

run();

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.