Aws PHP Sdk 3: S3 :: putObject (): AWS HTTP error: cURL error 6: Could not resolve host 's3.Ireland.amazonaws.com'

I am trying to upload an image to an S3 bucket using version 3 of the SDK but I am getting the following error:

Runtime error "PutObject" at " https://s3.Ireland.amazonaws.com/my-bucket-name/testFile.jpg "; AWS HTTP error: cURL error 6: Could not resolve host 's3.Ireland.amazonaws.com' (see http://curl.haxx.se/libcurl/c/libcurl-errors.html )

This is the first time I try to do this, so I'm not sure.

Uploading a file via AWS interface, its url is similar to https://s3-eu-west-1.amazonaws.com/my-bucket-name/testFileThroughWeb.jpg

. So it appears to be different from the one that the AWS SDK created for the PUT file (that is https://s3.Ireland.amazonaws.com/my-bucket-name/testFile.jpg

)

Another thing I would like to point out is the version that I pass to the S3Client constructor. It is instantiated by passing it the value stable

for the key version

, whereas in the bucket policy I use version: "2012-10-17"

.

This is the bucket policy configuration:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AddPerm",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::my-bucket-name/*"
        }
    ]
}

      

To save the image in the bucket, I use this code:

public function testS3Action()
{
    $fileToUpload = 'http://example.com/an/image.jpg';

    // Get the remote file extension
    $remoteImageExtension = explode('.', $fileToUpload);
    $remoteImageExtension = array_pop($remoteImageExtension);
    $fs = new Symfony\Component\Filesystem\Filesystem();
    $tempImage = tempnam(sys_get_temp_dir(), 'image.') . '.' . $remoteImageExtension;

    /**
     * From the Symfony container
     * @var GuzzleHttp\Client $client
     */
    $client = $this->get('guzzle.client');

    // Get and save file
    $client->get($fileToUpload, ['save_to' => $tempImage]);

    $tempImage = new Symfony\Component\HttpFoundation\File\File($tempImage);

    /**
     * From the Symfony container
     * @var Aws\S3\S3Client $s3
     */
    $s3 = $this->get('shq.amazon.s3');

    $params = [
        'Bucket' => $this->getParameter('amazon.s3.bucket'),
        'Key'    => 'testFile.jpg',
        'Body'   => $tempImage
    ];

    $result = $s3->putObject($params);

    return $result;
}

      

What could be causing the error I am getting? Why is the host https://s3.Ireland.amazonaws.com

guessed by S3Client wrong?

+3


source to share


1 answer


There is no AWS region like Ireland. Valid regions for S3 are listed on the Amazon website ; the one you are probably trying to use here is EU (Ireland) which will be represented in the region parameter as eu-west-1

.



+5


source







All Articles