3
votes

I'm trying to upload an image to an S3 bucket using the version 3 of the SDK, but I receive the following error:

Error executing "PutObject" on "https://s3.Ireland.amazonaws.com/my-bucket-name/testFile.jpg"; AWS HTTP error: cURL error 6: Couldn't 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 much confident.

Uploading a file through the AWS interface, its URL is something like https://s3-eu-west-1.amazonaws.com/my-bucket-name/testFileThroughWeb.jpg. So, it seems to be different from the one created by the AWS SDK to PUT the file (that is https://s3.Ireland.amazonaws.com/my-bucket-name/testFile.jpg)

Another thing I'd like to point out is the version I pass to the constructor of S3Client. Its instance is created passing to it the value stable for the key version while in the bucket policy I use version: "2012-10-17".

This is the configuration of the bucket policy:

{
    "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;
}

Which could be the cause of the error I'm getting? Why the host https://s3.Ireland.amazonaws.com guessed by the S3Client isn't correct?

2
The SDK shouldn't be "guessing" that value, because it's definitely invalid. There's no such endpoint as s3.Ireland.... You don't have something, somewhere, in your configuration or code where "Ireland" appears?Michael - sqlbot
I set it for the region parameter. When I instantiate the S3 client I pass it the value "Ireland" as region param.Aerendir

2 Answers

6
votes

There is no such AWS region as "Ireland". The valid regions for S3 are listed on Amazon's web site; the one you're probably trying to use here is EU (Ireland), which would be represented in a region parameter as eu-west-1.

0
votes

Maybe its late for you, but its new for others:

AWS HTTP error: cURL error 6: Couldn't resolve host 's3.Ireland.amazonaws.com' (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) error's meaning is that you have an error at your S3 URL / configuration. The service can't connect to S3 with your URL conf.

Such as my mistake, today I faced same error because of missing out a URL block.

In addition to this, if you use an alternative DC; that uses AWS platform on their side. You should ask them their own conf settings.