Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 GetObject without region resolves mostly empty response with 301 redirect. #1446

Closed
simonbuchan opened this issue Aug 18, 2020 · 4 comments · Fixed by #1591
Closed

S3 GetObject without region resolves mostly empty response with 301 redirect. #1446

simonbuchan opened this issue Aug 18, 2020 · 4 comments · Fixed by #1591
Assignees
Labels
guidance General information and guidance, answers to FAQs, or recommended best practices/resources.

Comments

@simonbuchan
Copy link
Contributor

Describe the bug

The SDK doesn't nicely handle missing (and incorrect?) regions, when this matters.

SDK version number
1.0.0-gamma.6

Is the issue in the browser/Node.js/ReactNative?
Node.js

Details of the browser/Node.js/ReactNative version
v14.4.0

To Reproduce (observed behavior)

Given simple code like the following, with valid values for credentials, Bucket, and Key, but where Bucket is not in the default region:

const client = new S3Client({ credentials });
const { Body, ...response } = await client.send(new S3.GetObjectCommand({ Bucket, Key });
console.log(Body.constructor.name);
console.log(response);

The response is:

Collapsed
IncomingMessage
{
  '$metadata': {
    httpStatusCode: 301,
    httpHeaders: {
      'x-amz-bucket-region': 'us-west-2',
      'x-amz-request-id': 'A9F640067EC487ED',
      'x-amz-id-2': '/Pt09qXAxECUFOj2e5FQGlh76Paxs+N6RL5O/kYYfl07cj6RA2QsNJHYV6y0Or6AAkrC6E4wHEo=',
      'content-type': 'application/xml',
      'transfer-encoding': 'chunked',
      date: 'Tue, 18 Aug 2020 04:56:25 GMT',
      server: 'AmazonS3'
    },
    requestId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  __type: 'GetObjectOutput',
  AcceptRanges: undefined,
  CacheControl: undefined,
  ContentDisposition: undefined,
  ContentEncoding: undefined,
  ContentLanguage: undefined,
  ContentLength: undefined,
  ContentRange: undefined,
  ContentType: 'application/xml',
  DeleteMarker: undefined,
  ETag: undefined,
  Expiration: undefined,
  Expires: undefined,
  LastModified: undefined,
  Metadata: {},
  MissingMeta: undefined,
  ObjectLockLegalHoldStatus: undefined,
  ObjectLockMode: undefined,
  ObjectLockRetainUntilDate: undefined,
  PartsCount: undefined,
  ReplicationStatus: undefined,
  RequestCharged: undefined,
  Restore: undefined,
  SSECustomerAlgorithm: undefined,
  SSECustomerKeyMD5: undefined,
  SSEKMSKeyId: undefined,
  ServerSideEncryption: undefined,
  StorageClass: undefined,
  TagCount: undefined,
  VersionId: undefined,
  WebsiteRedirectLocation: undefined
}

This is no fun to handle!

Expected behavior

I would expect one of raising an error (not sure which?) or silently handling the redirect.

@monken
Copy link

monken commented Aug 18, 2020

#1385

@AllanZhengYP AllanZhengYP self-assigned this Oct 8, 2020
@AllanZhengYP AllanZhengYP added the guidance General information and guidance, answers to FAQs, or recommended best practices/resources. label Oct 8, 2020
@AllanZhengYP
Copy link
Contributor

AllanZhengYP commented Oct 8, 2020

Hi @monken @simonbuchan , in v3 SDK we have decided that the SDK base client won't follow the redirection automatically like previous SDK. But you are right, we should've throw that instead of swallow it. We will prioritize it before moving out of preview.

I will close this one as it's duplicated to #1385

@trivikr
Copy link
Member

trivikr commented Oct 23, 2020

Verified that the error is thrown as expected in @aws-sdk/client-s3@1.0.0-rc.2

Code
const AWS = require("aws-sdk");
const { S3 } = require("@aws-sdk/client-s3");

(async () => {
  const region = "us-east-1";
  const Bucket = `test-bucket-${Math.ceil(Math.random() * 10 ** 10)}`;
  const Key = `Key`;
  const Body = `Body`;

  const v2Client = new AWS.S3({ region });
  const v3Client = new S3({ region });

  await v3Client.createBucket({ Bucket });
  // Waiters missing in v3.
  await v2Client.waitFor("bucketExists", { Bucket }).promise();

  await v3Client.putObject({ Bucket, Key, Body });
  try {
    const client = new S3({ region: "us-west-2" });
    console.log(await client.getObject({ Bucket, Key }));
  } catch (e) {
    console.log(e);
  }
  await v3Client.deleteObject({ Bucket, Key });

  await v3Client.deleteBucket({ Bucket });
})();
Output
PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
    at deserializeAws_restXmlGetObjectCommandError (/Users/trivikr/workspace/temp/node_modules/@aws-sdk/client-s3/dist/cjs/protocols/Aws_restXml.js:5748:41)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async /Users/trivikr/workspace/temp/node_modules/@aws-sdk/middleware-serde/dist/cjs/deserializerMiddleware.js:12:20
    at async /Users/trivikr/workspace/temp/node_modules/@aws-sdk/middleware-signing/dist/cjs/middleware.js:12:24
    at async StandardRetryStrategy.retry (/Users/trivikr/workspace/temp/node_modules/@aws-sdk/middleware-retry/dist/cjs/defaultStrategy.js:55:46)
    at async /Users/trivikr/workspace/temp/node_modules/@aws-sdk/middleware-logger/dist/cjs/loggerMiddleware.js:6:22
    at async /Users/trivikr/workspace/temp/testBucket.js:20:17 {
  Code: 'PermanentRedirect',
  Endpoint: 's3.amazonaws.com',
  Bucket: 'test-bucket-4637162357',
  RequestId: '8CD79E3FE41F19A2',
  HostId: 'bqEZ1ipwy0t/WSR4Gk4lil4XUG5hIlAfkj5+eCIt3CdCKmM4gMilSuq5nBYXKIyYK3ZRN5hh63M=',
  '$fault': 'client',
  '$metadata': {
    httpStatusCode: 301,
    httpHeaders: {
      'x-amz-bucket-region': 'us-east-1',
      'x-amz-request-id': '8CD79E3FE41F19A2',
      'x-amz-id-2': 'bqEZ1ipwy0t/WSR4Gk4lil4XUG5hIlAfkj5+eCIt3CdCKmM4gMilSuq5nBYXKIyYK3ZRN5hh63M=',
      'content-type': 'application/xml',
      'transfer-encoding': 'chunked',
      date: 'Fri, 23 Oct 2020 02:30:47 GMT',
      server: 'AmazonS3'
    },
    requestId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  }
}

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
guidance General information and guidance, answers to FAQs, or recommended best practices/resources.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants