Skip to content

Cant create S3 bucket #589

Open
Open

Description

@terbooter
let client = require('pkgcloud').storage.createClient({
    provider: 'amazon',
    keyId: 'aws-id', // access key id
    key: 'aws-key', // secret key
    region: 'us-west-2' // region
});

// Give list of containers
client.getContainers((err, containers) => {
    console.log(err);
    console.log(containers);
});

// Throw error
client.createContainer({name: 'test-name'}, function (err, container) {
    console.log(err);
    console.log(container);
});

Error message:

{ TypeError: bucket.indexOf is not a function
    at Request.validateBucketName (c:\ubuntu\klassapp\pkgcloud-test\node_modules\aws-sdk\lib\services\s3.js:166:39)
    at Request.callListeners (c:\ubuntu\klassapp\pkgcloud-test\node_modules\aws-sdk\lib\sequential_executor.js:105:20)
    at callNextListener (c:\ubuntu\klassapp\pkgcloud-test\node_modules\aws-sdk\lib\sequential_executor.js:95:12)
    at c:\ubuntu\klassapp\pkgcloud-test\node_modules\aws-sdk\lib\event_listeners.js:85:9
    at finish (c:\ubuntu\klassapp\pkgcloud-test\node_modules\aws-sdk\lib\config.js:320:7)
    at c:\ubuntu\klassapp\pkgcloud-test\node_modules\aws-sdk\lib\config.js:338:9
    at Credentials.get (c:\ubuntu\klassapp\pkgcloud-test\node_modules\aws-sdk\lib\credentials.js:126:7)
    at getAsyncCredentials (c:\ubuntu\klassapp\pkgcloud-test\node_modules\aws-sdk\lib\config.js:332:24)
    at Config.getCredentials (c:\ubuntu\klassapp\pkgcloud-test\node_modules\aws-sdk\lib\config.js:352:9)
    at Request.VALIDATE_CREDENTIALS (c:\ubuntu\klassapp\pkgcloud-test\node_modules\aws-sdk\lib\event_listeners.js:80:26)
  message: 'bucket.indexOf is not a function',
  code: 'TypeError',
  time: 2017-11-15T09:02:47.158Z,
  originalError:
   { message: 'Expected params.Bucket to be a string',
     code: 'InvalidParameterType',
     time: 2017-11-15T09:02:47.157Z } }

Activity

  1. gustxyz commented on Jul 22, 2018

    @gustxyz

    Hey there @terbooter. To create a container just pass in the name as a string, not as an object.

  2. gustxyz commented on Jul 22, 2018

    @gustxyz

    Issue should be closed.

  3. terbooter commented on Jul 23, 2018

    @terbooter
    Author

    According to this example https://github.com/pkgcloud/pkgcloud/blob/master/examples/storage/rackspace.js

    // 1 -- to create a container
    client.createContainer({
      name: 'sample-container-test',
      metadata: {
        callme: 'maybe'
      }
    }, function (err, container) {
      if (err) {
        console.dir(err);
        return;
      }
    

    method createContainer accepts object not string

    If createContainer has different signatures for different providers it should be mentioned in docs or in according example at least.
    So issue is still here

  4. gustxyz commented on Aug 3, 2018

    @gustxyz

    After looking at the docs a bit.. passing it in the way you specified should work actually, apologies. I'm going to take a look at this today after work and see whats up. I totally agree with you on the documentation thing.. that needs to be updated.

    I'll see about cleaning that up as well, thank you!

  5. gustxyz commented on Aug 4, 2018

    @gustxyz

    So I've dug into the code a bit.. indeed there is a bug. The create container function checks whether or not the options argument is of type storage.Container. The issue is that storage.container is undefined.

    s3 createContainer

    exports.createContainer = function (options, callback) {
      var containerName = options instanceof storage.Container ? options.name : options,
        self = this;
    
      self.s3.createBucket({
        Bucket: containerName
      }, function(err) {
        return err
          ? callback(err)
          : callback(null, new (storage.Container)(self, options));
      });
    };
    
    

    All clients should have a standardized way of checking that options parameter. It should be changed to follow the openstack createContainer format. I've tested this change locally and it works as expected.

    Openstack createContainer

    exports.createContainer = function (options, callback) {
      var containerName = typeof options === 'object' ? options.name : options,
          self = this;
    
      var createContainerOpts = {
        method: 'PUT',
        container: containerName
      };
    
      if (options.metadata) {
        createContainerOpts.headers = self.serializeMetadata(self.CONTAINER_META_PREFIX, options.metadata);
      }
    
      this._request(createContainerOpts, function (err) {
        return err
          ? callback(err)
          : callback(null, new self.models.Container(self, { name: containerName, metadata: options.metadata }));
      });
    };
    
    
  6. gustxyz commented on Aug 4, 2018

    @gustxyz

    I pulled down the master branch but I cant get it to pass TravisCi(With no changes to the code base). This is 'options' issue is an easy fix and I like to get it out soon but unfortunately this has stalled me.

    Any thoughts @rosskukulinski ? Looks like youve fixed these Travis-ci issues in the past.

  7. gustxyz commented on Aug 4, 2018

    @gustxyz

    Its been posted elsewhere but this is what Travis is looking like..

     733 passing (9s)
      35 pending
      2 failing
    
      1) pkgcloud/openstack/storage/ The openstack Storage client copy should copy within the same container:
         Uncaught Error: No Match For: POST /v2.0/tokens
          at IncomingMessage.<anonymous> (/Users/alexanderlong/Documents/GitHub/pkgcloud/node_modules/hock/lib/hock.js:364:15)
          at IncomingMessage.emit (events.js:182:13)
          at endReadableNT (_stream_readable.js:1081:12)
          at process._tickCallback (internal/process/next_tick.js:63:19)
    
      2) pkgcloud/openstack/storage/ The openstack Storage client copy "after each" hook:
         Error: timeout of 4000ms exceeded
          at Timeout.<anonymous> (/Users/alexanderlong/Documents/GitHub/pkgcloud/node_modules/mocha/lib/runnable.js:158:19)
          at ontimeout (timers.js:427:11)
          at tryOnTimeout (timers.js:289:5)
          at listOnTimeout (timers.js:252:5)
          at Timer.processTimers (timers.js:212:10)
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions