I'm trying to connect to an AWS version 3 SDK bucket.
But, I receive the below error:
PHP Fatal error: Uncaught exception 'Aws\S3\Exception\S3Exception' with message 'Error executing "PutObject" on "https://s3.oregon.amazonaws.com/my-buekct-test/hello_world.txt"; AWS HTTP error: cURL error 6: Could not resolve host: s3.oregon.amazonaws.com (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)'
This is my code, just simple.
<?php
header('Content-Type: text/plain; charset=utf-8');
// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';
$s3 = new Aws\S3\S3Client([
'region' => 'Oregon',
'version' => 'latest',
'credentials' => [
'key' => 'Enter the key',
'secret' => 'Enter the Secret key'
]
]);
// Send a PutObject request and get the result object.
$key = 'hello_world.txt';
$result = $s3->putObject([
'Bucket' => 'my-buekct-test',
'Key' => $key,
'Body' => 'this is the body!'
]);
// Print the body of the result by indexing into the result object.
echo $result['Body'];
I'm using AWS centos, php 5.5.21, apache 2.4.10
Could you help point out where did I go wrong?
To troubleshoot this error, check the following: Confirm that you're using the correct AWS Region and Amazon S3 endpoint. Verify that your network can connect to those Amazon S3 endpoints. Verify that your DNS can resolve to those Amazon S3 endpoints.
An S3 bucket can be accessed through its URL. The URL format of a bucket is either of two options: http://s3.amazonaws.com/[bucket_name]/ http://[bucket_name].s3.amazonaws.com/
An S3 VPC endpoint provides a way for an S3 request to be routed through to the Amazon S3 service, without having to connect a subnet to an internet gateway. The S3 VPC endpoint is what's known as a gateway endpoint.
Try with below code you need to change region only
<?php
header('Content-Type: text/plain; charset=utf-8');
// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';
$s3 = new Aws\S3\S3Client([
'region' => 'us-west-2',
'version' => 'latest',
'credentials' => [
'key' => 'Enter the key',
'secret' => 'Enter the Secret key'
]
]);
// Send a PutObject request and get the result object.
$key = 'hello_world.txt';
$result = $s3->putObject([
'Bucket' => 'my-buekct-test',
'Key' => $key,
'Body' => 'this is the body!'
]);
// Print the body of the result by indexing into the result object.
echo $result['Body'];
'region' => 'us-west-2', // this thing i only updated
you can find region information of aws from here : http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
Hope this will help!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With