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 doesn't follow 301s from us-east-1 to eu #1802

Closed
alexforsyth opened this issue Dec 17, 2020 · 2 comments
Closed

S3 doesn't follow 301s from us-east-1 to eu #1802

alexforsyth opened this issue Dec 17, 2020 · 2 comments
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. guidance General information and guidance, answers to FAQs, or recommended best practices/resources.

Comments

@alexforsyth
Copy link
Contributor

alexforsyth commented Dec 17, 2020

Describe the bug
A clear and concise description of what the bug is.

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

(async () => {
  const region = "us-east-1";
  const client = new S3({ region, logger: console });

  const Bucket = `test-bucket-${Date.now()}`;
  await client.createBucket({
    Bucket,
    CreateBucketConfiguration: {
      LocationConstraint: "EU",
    },
  });

  try {
    await client.headBucket({ Bucket });
  } catch (error) {
    // THROWS 301
    console.log(error);
  }
})();

The SDK does not follow 301s

SDK version number

3.0.0

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

Details of the browser/Node.js/ReactNative version
Paste output of npx envinfo --browsers or node -v or react-native -v

To Reproduce (observed behavior)
Steps to reproduce the behavior (please share code or minimal repo)

Expected behavior
A clear and concise description of what you expected to happen.
The sdk should follow a 301 and get the correct result back

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

@alexforsyth alexforsyth changed the title S3 doesn't follow 301s S3 doesn't follow 301s from us-east-1 to eu Dec 17, 2020
@alexforsyth alexforsyth changed the title S3 doesn't follow 301s from us-east-1 to eu S3 doesn't follow 301s from us-east-1 to eu Dec 17, 2020
@AllanZhengYP
Copy link
Contributor

AllanZhengYP commented Dec 17, 2020

This is expected. Although S3 buckets are globally unique, you need create bucket in a specific region. By default, a bucket will be created in the region where your S3 client's region is. In the example above, it is us-east-1. When a bucket is create with LocationConstraint configuration, the bucket is created in the specified region(e.g. EU or eu-west-1). Since the newly created bucket locates in eu-west-1, you need to head bucket with correct region(bucket.s3.eu-west-1.amazonaws.com), otherwise you will get a 301 response.

To make to code above work, you have to head bucket to the correct region:

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

(async () => {
  const region = "us-east-1";
  const targetRegion = "eu-west-1";
  const client = new S3({ region, logger: console });

  const Bucket = `test-bucket-${Date.now()}`;
  await client.createBucket({
    Bucket,
    CreateBucketConfiguration: {
      LocationConstraint: targetRegion,
    },
  });

  const newClient = new S3({region: targetRegion});
  await newClient.headBucket({ Bucket });
})();

In v2, we implemented a lot of hacky logic to make the S3 client behaves like a global client, but it may confuse the users, espacially those having knowledge of other AWS tools. So we remove the follow-the-redirect feature in v3. If we see more feature requests, we can provide a higher level library to support global client. I created a feature request in separate ticket: #1807

@AllanZhengYP AllanZhengYP added guidance General information and guidance, answers to FAQs, or recommended best practices/resources. closing-soon This issue will automatically close in 4 days unless further comments are made. labels Dec 17, 2020
@github-actions
Copy link

github-actions bot commented Jan 8, 2021

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 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. guidance General information and guidance, answers to FAQs, or recommended best practices/resources.
Projects
None yet
Development

No branches or pull requests

2 participants