padam thapa
padam thapa

Reputation: 1477

Error when uploading file to S3: PutObject error

Below is the error every-time I try to upload an image to my bucket

Error executing \"PutObject\" on "https://xxxxxxbucket.s3.us-west-1.amazonaws.com/img1.png"; AWS HTTP error: cURL error 6:

(see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

Now first, cURL error 6 according to curl error html link in error says "Couldn't resolve host. The given remote host was not resolved."

Every issue on forums regarding cURL error 6 was mostly happening due to wrong name of 'region' being provided. In my case it is correct 'us-west-1' for North California. I have been using other buckets in same region for other apps. This is another reason why I am very puzzled.

Second, my IAM user has access to that bucket. I even used admin access keys to see if something was wrong with my policy for my iAM user. Same error. I also wondered if anything wrong with permission then I should have gotten "forbidden error" instead of "unresolved error". I set my bucket to public explicitly just to debug and same error.

Third, I tried mutiple ways to upload to s3:

//First way
$disk = Storage::disk('s3');
$disk->put($filename, file_get_contents($value -> getRealPath()));

//Second way
$client = new S3Client([
'credentials' => [
    'key'    => 'xxxxx',
    'secret' => 'xxxxxx'
],
    'region' => 'us-west-1',
    'version' => 'latest',
]);

$adapter = new AwsS3Adapter($client, 'xxxxxbucket');
$filesystem = new Filesystem($adapter);
$filesystem -> put($filename, file_get_contents($value -> getRealPath()));

Lastly, I have checked received files on my Laravel end and they are fine.

I am testing on local machine. I deployed the code to my beanstalk environment to see If it was issue on my local development side but staging server giving same error.

What might I be doing wrong?

Upvotes: 1

Views: 651

Answers (2)

padam thapa
padam thapa

Reputation: 1477

I found the cause in local development case. It is silly. It seems cURL of my mac and php cURL were different version. mac cURL is 7.54.0 and php using cURL is 7.65.3

So i uninstalled last cURL version

brew uninstall curl-openssl --ignore-dependencies

and restarted the php

brew services restart php

Now Its all working.

In case where I mentioned beanstalk was not working too, it was silly ignorant mistake about something else error in code. This one really was my blunder because if I paid more close attention in this case then I could have saved my time a lot.

Upvotes: 2

Prathap Reddy
Prathap Reddy

Reputation: 1739

I could only think of couple of possible issues

  • From local: If you are behind corporate proxy and not able to ping the respective aws host.
  • From deployed beanstalk: If you are inside VPC and not able to access host outside of it directly.

Upvotes: 0

Related Questions