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.putObject to a different region fails silently #1385

Closed
monken opened this issue Jul 15, 2020 · 3 comments
Closed

s3.putObject to a different region fails silently #1385

monken opened this issue Jul 15, 2020 · 3 comments
Assignees
Labels
bug This issue is a bug. High Priority

Comments

@monken
Copy link

monken commented Jul 15, 2020

Describe the bug
When calling s3.putObject on a bucket in a different region the call will succeed but the file is not actually uploaded. The response from S3 is a 301 redirect and the SDK accepts that as a valid response.

SDK version number
1.0.0-gamma.4

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

Expected behavior
Throw an exception or follow the redirect and upload to the correct region. I'd prefer the exception because it involves less magic.

@monken monken changed the title s3.putObject to a different region doesn't fail s3.putObject to a different region fails silently Jul 15, 2020
@AllanZhengYP AllanZhengYP added the bug This issue is a bug. label Jul 27, 2020
@AllanZhengYP
Copy link
Contributor

Hi @monken
Like I mentioned in #1446 (comment), we fix this by throwing redirection response instead of swallow them.

@trivikr
Copy link
Member

trivikr commented Oct 23, 2020

Verified that putObject fails with 301 in @aws-sdk/client-s3@1.0.0-rc.2 if called on different region

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

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

  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_restXmlPutObjectCommandError (/Users/trivikr/workspace/temp/node_modules/@aws-sdk/client-s3/dist/cjs/protocols/Aws_restXml.js:7583: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:19:17 {
  Code: 'PermanentRedirect',
  Endpoint: 's3.amazonaws.com',
  Bucket: 'test-bucket-9250623973',
  RequestId: 'EB2260124CD3B45E',
  HostId: 'P5+KgO7yuxIhf9LxwqBWwqU050/P1662KPMqJonXhLrya4P09vqAXSEERQ2VgceAtY42IwlmM9M=',
  '$fault': 'client',
  '$metadata': {
    httpStatusCode: 301,
    httpHeaders: {
      'x-amz-bucket-region': 'us-east-1',
      'x-amz-request-id': 'EB2260124CD3B45E',
      'x-amz-id-2': 'P5+KgO7yuxIhf9LxwqBWwqU050/P1662KPMqJonXhLrya4P09vqAXSEERQ2VgceAtY42IwlmM9M=',
      'content-type': 'application/xml',
      'transfer-encoding': 'chunked',
      date: 'Fri, 23 Oct 2020 02:33:14 GMT',
      connection: 'close',
      server: 'AmazonS3'
    },
    requestId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  }
}

@trivikr trivikr closed this as completed Oct 23, 2020
@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
bug This issue is a bug. High Priority
Projects
None yet
Development

No branches or pull requests

3 participants