2

I am trying to upload error file in AWSS3 but it shows error like "The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint: "test9011960909.s3.amazonaws.com"."

i also specified 'region' => 'us-east-1' but still same error occurs.

it is working when i specify

'Bucket'       => $this->bucket,

but i wanted to upload file in sub-folder of main bucket

'Bucket'       => $this->bucket . "/" . $PrefixFolderPath,

i already applied approved answer from AWS S3: The bucket you are attempting to access must be addressed using the specified endpoint

but still getting same error, i am using php

Code :

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

class AWSS3Factory {

    private $bucket;
    private $keyname;

    public function __construct() {
        $this->bucket = AWSS3_BucketName;
        $this->keyname = AWSS3_AccessKey;
        // Instantiate the client.
    }

    public function UploadFile($FullFilePath,$PrefixFolderPath="") {
        try {
            $s3 = S3Client::factory(array(
                'credentials' => array(
                    'key'    => MYKEY,
                    'secret' => MYSECKEY,
                    'region' => 'eu-west-1',
                )
            ));

            // Upload data.
            $result = $s3->putObject(array(
                'Bucket'       => $this->bucket . "/" . $PrefixFolderPath,
                'Key'          => $this->keyname,
                'SourceFile'   => $FullFilePath,
                'StorageClass' => 'REDUCED_REDUNDANCY'
            ));
            return true;
            // Print the URL to the object.
            //echo $result['ObjectURL'] . "\n";
        } catch (S3Exception $e) {
            echo $e->getMessage() . "\n";
        }
    }
 }
Community
  • 1
  • 1
Juned Ansari
  • 5,035
  • 7
  • 56
  • 89
  • 1
    Possible duplicate of [AWS S3: The bucket you are attempting to access must be addressed using the specified endpoint](http://stackoverflow.com/questions/25027462/aws-s3-the-bucket-you-are-attempting-to-access-must-be-addressed-using-the-spec) – Imran Saeed Mar 20 '17 at 11:52
  • i already applied approved answer, but still getting same error thats why post this question, i am using php. – Juned Ansari Mar 20 '17 at 12:01
  • Given that this is the only explanation by AWS for this error: http://docs.aws.amazon.com/redshift/latest/dg/s3serviceexception-error.html#bucket-in-different-region and that's the only time myself (and most of the others) have seen it, I can't think of other reasons. Check you AWS console and raise a ticket with AWS if you think you are accessing from correct region. – Imran Saeed Mar 20 '17 at 12:06
  • Go to the console and check your bucket's region, again. – Michael - sqlbot Mar 21 '17 at 03:16
  • login is correct – Juned Ansari Mar 21 '17 at 05:22

2 Answers2

1

You must add $PrefixFolderPath not to 'Bucket' but to 'Key':

$result = $s3->putObject(array(
    'Bucket'       => $this->bucket,
    'Key'          => $PrefixFolderPath . "/" . $this->keyname,
    'SourceFile'   => $FullFilePath,
    'StorageClass' => 'REDUCED_REDUNDANCY'
));
cn007b
  • 16,596
  • 7
  • 59
  • 74
1

You must create s3 instance in another way, like this:

$s3 = S3Client::factory([
    'region'      => '',
    'credentials' => ['key' => '***', 'secret' => '***'],
    'version' => 'latest',
]);
noname
  • 28
  • 4