Aws-sdk-js: getObject giving invalid bucket with aws-sdk on version >2.67.0

Created on 14 Jun 2017  路  5Comments  路  Source: aws/aws-sdk-js

new AWS.S3(awsOptions).getObject(queryParms) causing error "InvalidBucket: Bucket names cannot contain forward slashes." while fetching a file from a bucket named as 'a/b/c'.While same bucket name works fine when we upload a file with new AWS.S3(awsOptions).upload() method with aws-sdk version 2.69.
The same bucket name working fine with sdk version 2.67. Below are the stackTrace
StackTrace=InvalidBucket: Bucket names cannot contain forward slashes. Bucket: test-a/devdocuments1/testFolder
at Request.validateBucketName (d:\testProject\node_modules\aws-sdk\lib\services\s3.js:167:28)

Let me knwo if you need further details . Please resolve

guidance

Most helpful comment

@KafaltiyaMahesh
S3 Buckets are not allowed to contain forward slashes in their name. In your example where the bucket is named a/b/c, the bucket would actually be a, and the key's prefix would be b/c/.

There has been some discussion about this here:
https://github.com/aws/aws-sdk-js/issues/1046#issuecomment-234098432

There are 2 ways you can immediately get around this issue. The recommended way would be to update the bucket names in your code so they only include the bucket name, and not part of an object's key. The other would be to configure your S3 client to use signatureVersion v2.

Example:

var s3 = new AWS.S3({
  signatureVersion: 'v2'
});

All 5 comments

@KafaltiyaMahesh
S3 Buckets are not allowed to contain forward slashes in their name. In your example where the bucket is named a/b/c, the bucket would actually be a, and the key's prefix would be b/c/.

There has been some discussion about this here:
https://github.com/aws/aws-sdk-js/issues/1046#issuecomment-234098432

There are 2 ways you can immediately get around this issue. The recommended way would be to update the bucket names in your code so they only include the bucket name, and not part of an object's key. The other would be to configure your S3 client to use signatureVersion v2.

Example:

var s3 = new AWS.S3({
  signatureVersion: 'v2'
});

@chrisradek Thanks for the clarification. Only one confusion ; why are you allowing forward slashes in the bucketname while uploading file ?

@KafaltiyaMahesh
It turned out there was a bug with s3.upload where just the upload method would always default to using signature version 2, instead of 4 as intended. #1587 fixes this so that upload will always use the same signature version that the client it was called on would use.

1587 also adds back in the ability to specify forward slashes in a bucket name as long as a Key is also provided (even if the Key is an empty string).

However! This was only done to maintain backwards compatibility with behavior prior to updating S3 to use signature version 4 by default. Including the key prefix in a bucket name is not a documented feature, and any new code should avoid doing so. This behavior will be removed the next time we do a major version bump since it was never intended to allow keys to be specified as part of the bucket.

@chrisradek Thanks man..! I have changed my code. Now using key prefix for nested directory structure which would be supported by you in later versions also.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

Was this page helpful?
0 / 5 - 0 ratings