LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-19-2020, 01:08 PM   #1
redd9
Member
 
Registered: Nov 2013
Location: Canada
Distribution: RHEL, Ubuntu
Posts: 212
Blog Entries: 1

Rep: Reputation: 82
cURL problem in EC2 on RHEL 8


Hi everyone, I'm having a weird problem again and I'm sure I'm doing something dumb.

Basically, I have a PHP script running on an RHEL 8 EC2 box that is supposed to grab a video from an S3 bucket and display it in a browser.

However, I get the error
Code:
Error executing "GetObject" on "https://my-bucket.s3.us-east-2.amazonaws.com/Folder/Item.mp4"; AWS HTTP error: cURL error 7: (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
when I try to access it. If I just copy that URL into a browser, I can access it no problem. I can also curl to download the file on my EC2 box directly.

I then tried running a script to curl google.com and server it up in a browser. That also failed, with no error. However, it succeeded when I ran it on my desktop.

I have even tried completely opening up the firewall on my EC2 instance, hardcoding credentials, and making the object public in S3, but no luck. I still suspect this may be some kind of permissions issue - any ideas on what it could be?

My script here:
PHP Code:
<?php
ini_set
('display_errors',1);
require 
'vendor/autoload.php';

use 
Aws\S3\S3Client;
use 
Aws\S3\Exception\S3Exception;

$bucket 'my-bucket';
$keyname 'Folder/File.mp4';

$s3 = new S3Client([
    
'version' => 'latest',
    
'region'  => 'us-east-2',
    
'credentials' => [
            
'key' => 'ABC123ABC123ABC123ABC123',
            
'secret' => 'ABC123ABC123ABC123ABC123ABC123ABC123',
    ],
]);

try {
    
$result $s3->getObject([
        
'Bucket' => $bucket,
        
'Key'    => $keyname
    
]);

    
header("Content-Type: {$result['ContentType']}");
    echo 
$result['Body'];
} catch (
S3Exception $e) {
    echo 
$e->getMessage() . PHP_EOL;
}
?>
Update: Forgot to add my script is essentially copied and pasted from the Amazon website, I checked in phpinfo that I have cURL support, and print_r(curl_getinfo($ch)); produces this output: Array ( [url] => http://google.com/ [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [redirect_url] => [primary_ip] => [certinfo] => Array ( ) [primary_port] => 0 [local_ip] => [local_port] => 0 )

Seems to be the same problem that this person has https://www.sitepoint.com/community/t/curl-not-working/3604/10 except there is no proxy (unless AWS adds one somehow?)

Last edited by redd9; 03-19-2020 at 02:18 PM. Reason: Adding more info
 
Old 03-20-2020, 07:12 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,873
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
I don't have such S3 so I can only guess: you should add error-check after line 18
 
Old 03-20-2020, 09:30 AM   #3
redd9
Member
 
Registered: Nov 2013
Location: Canada
Distribution: RHEL, Ubuntu
Posts: 212

Original Poster
Blog Entries: 1

Rep: Reputation: 82
Sorry, I'm new to PHP - what error check should I add? I have try/catch and tried
Code:
or die
which just killed it.

I also tried just now running the script on my desktop and it worked perfectly there.
 
Old 03-20-2020, 09:45 AM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555

You're getting an error saying curl can't connect, when executed by a PHP-based AWS library.

You can connect to AWS via curl on command line, and can also use PHP curl to connect to Google.

Sounds like the next thing to do is PHP curl without the AWS library involved.

i.e. take the working curl command you have and convert it to PHP curl.
You can automate that with https://incarnate.github.io/curl-to-php/

If that works, it's likely either a bug or misconfiguration with the AWS library.
If it doesn't, it may be an issue with PHP curl.


Quote:
Originally Posted by redd9 View Post
I also tried just now running the script on my desktop and it worked perfectly there.
Check whether your desktop is running the exact same versions of OS, PHP, libcurl, and the AWS library code?

If it works on one and not on the other you need to identify all differences involved and rule them out one by one.


Last edited by boughtonp; 03-20-2020 at 09:52 AM.
 
1 members found this post helpful.
Old 03-20-2020, 01:21 PM   #5
redd9
Member
 
Registered: Nov 2013
Location: Canada
Distribution: RHEL, Ubuntu
Posts: 212

Original Poster
Blog Entries: 1

Rep: Reputation: 82
Thanks everyone for your replies!

It turns out that running my script on a VM configured exactly the same as my ec2 instance does *not* work. I'll do more troubleshooting and try downgrading my curl/php to see if I can crack this one...
 
Old 03-22-2020, 10:13 AM   #6
redd9
Member
 
Registered: Nov 2013
Location: Canada
Distribution: RHEL, Ubuntu
Posts: 212

Original Poster
Blog Entries: 1

Rep: Reputation: 82
My attempts to downgrade were unsuccessful. I got it working for now by running a windoze instance. Hopefully I can switch to Linux in the future but I'll mark this as solved for now.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Curl-OPENSSL1 update for SUSE 11 SP4 - Backdates Curl DaveUSC SUSE / openSUSE 5 05-31-2019 02:04 PM
[SOLVED] Slackware ARM 14.2 - Updates Rollback - curl-7.57.0 - curl-7.58.0 abga Slackware - ARM 13 02-02-2018 11:44 AM
CentOS 6.7 has really OLD curl. Best way to update curl? sneakyimp Linux - Server 4 04-26-2016 03:06 PM
Categorize the output of ec2-describe-images or ec2-describe-instances amit.naudiyal Linux - General 0 01-15-2012 12:35 AM
cURL: Server has many IPs, how would I make a cURL script use those IPs to send data? guest Programming 0 04-11-2009 11:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration