jeanbmar / s3-sync-client

AWS CLI s3 sync command for Node.js
MIT License
83 stars 22 forks source link

simple s3 sync region error #29

Closed YonatanHanan closed 2 years ago

YonatanHanan commented 2 years ago

Hi,

I'm trying to copy one s3 bucket to another one. this is the code:

const { S3Client } = require('@aws-sdk/client-s3');
const S3SyncClient = require('s3-sync-client');

...

   try {
      process.env.AWS_REGION = 'us-east-1';
      // const s3Client = new S3Client({ region: 'us-east-1' });
      const s3Client = new S3Client({
        region: 'us-east-1',
        // endpoint: `http:/s/users-files-prod.s3-website.us-east-1.amazonaws.com`,
      });
      const { sync } = new S3SyncClient({ client: s3Client, region: 'us-east-1' });

      await sync(`s3://users-files-prod/${srcPath}`, `s3://${destPath}`);
    } catch (error) {
      console.log(error);
    }

but i get

The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

and the request was to users-files-prod.s3.eu-central-1.amazonaws.com and not to us-east-1

what am i doing wrong?

jeanbmar commented 2 years ago

Hello,

Are you 100% sure about your bucket name? eu-central-1 and us-east-1 are in the same partition (https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html). It should be impossible to have 2 buckets with the same name.

Can you call the list objects command (https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/listobjectsv2commandinput.html#bucket) from the s3Client on the bucket?

jeanbmar commented 2 years ago

Yep there's 100% an error with the bucket name or the region.

http://users-files-prod.s3-website.us-east-1.amazonaws.com/ returns:

400 Bad Request
Code: IncorrectEndpoint
Message: The specified bucket exists in another region. Please direct requests to the specified endpoint.
Endpoint: users-files-prod.s3-website.eu-central-1.amazonaws.com
RequestId: E9CJDXTW9HXES157
HostId: J0QSQbeCzfEkdgSYITFIbK0A69ZbnOkZ4j55tsj9YaIMRdvKRsXVfHQFqG47JkcLTuFlyrE7w+c=
YonatanHanan commented 2 years ago

the bucket is private, so maybe the error is because of that?

jeanbmar commented 2 years ago

Nope. Even private buckets that don't have a website respond to this query. Look: http://s3-sync-client.s3-website.eu-west-3.amazonaws.com. If your bucket name is really users-files-prod you should contact Amazon because it's theoretically impossible.

YonatanHanan commented 2 years ago

OK, is it possible to sync a "folder" inside an s3 bucket? await sync(s3://users-files-prod/${srcPath},s3://${destPath});

jeanbmar commented 2 years ago

Yes and it is straight forward for simple cases. You can use filters and relocations options for complex cases (e.g. if you want to filter some data or change the target bucket structure). You have many examples in the test folder of the repo.

YonatanHanan commented 2 years ago

ok thanks for the help :)