Skip to content
Advertisement

Aws PHP Sdk 3: S3::putObject(): AWS HTTP error: cURL error 6: Couldn’t resolve host ‘s3.Ireland.amazonaws.com’

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 SymfonyComponentFilesystemFilesystem();
    $tempImage = tempnam(sys_get_temp_dir(), 'image.') . '.' . $remoteImageExtension;

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

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

    $tempImage = new SymfonyComponentHttpFoundationFileFile($tempImage);

    /**
     * From the Symfony container
     * @var AwsS3S3Client $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?

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement