Skip to content

Instantly share code, notes, and snippets.

@viccherubini
Created September 24, 2014 15:06
Show Gist options
  • Save viccherubini/e3107493f078516555f3 to your computer and use it in GitHub Desktop.
Save viccherubini/e3107493f078516555f3 to your computer and use it in GitHub Desktop.
AWS SDK base_url Questions
<?php
// Configuration, using AWS SDK 2.6.16
return [
'includes' => ['_aws'],
'services' => [
'default_settings' => [
'params' => [
'key' => 'xxx',
'secret' => 'yyyy',
'base_url' => 'http://files.example.com'
]
]
]
];
// Assume $s3Client is constructed with config above.
$result = $s3Client->putObject([
'Bucket' => 'files.example.com',
'Key' => 'image.jpg',
'SourceFile' => '/path/to/image.jpg',
'ContentType' => 'image/jpeg',
'ACL' => CannedAc::PUBLIC_READ
]);
// Receive this error:
// [curl] 6: Couldn't resolve host 'files.example.com.files.example.com' [url] http://files.example.com.files.example.com/image.jpg
// It seems it attempts to create the URL as: scheme://<bucket-name>.<base-url>.
// If you have a CNAME that points files.example.com to files.example.com.s3.amazonaws.com this won't work.
@yellow1912
Copy link

@jeremeamia 1 year later and I'm finding this info useful. I setup cname with aws sdk php using this information here:

aws/aws-sdk-php#347

The getObjectUrl works fine yet the upload part gives me the exact same issue as described above. I will try your solution now. I wonder if this is caused by me using SDK 2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment