aws / aws-sdk-php

Official repository of the AWS SDK for PHP (@awsforphp)
http://aws.amazon.com/sdkforphp
Apache License 2.0
6k stars 1.22k forks source link

runInstances Error:Call to undefined method Error::getResponse() in yii2 #2319

Closed alahoo closed 2 years ago

alahoo commented 3 years ago

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug Call runInstances Error:Call to undefined method Error::getResponse() in yii2

Version of AWS SDK for PHP? Version 3.194.0

Version of PHP (php -v)? PHP 7.2.0 (cli) (built: Dec 15 2017 18:34:34) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies

To Reproduce (observed behavior) `<?php require(DIR . '/vendor/autoload.php'); require(DIR . '/vendor/yiisoft/yii2/Yii.php');

$config = require(DIR . '/config/web.php'); //(new yii\web\Application($config))->run(); //$yii2App = new yii\web\Application($config);

require(DIR . '/assets/inc/aws/aws-autoloader.php');

use Aws\Credentials\Credentials; use Aws\Ec2\Ec2Client;

$credentials = new Credentials("ID","KEY"); $ec2Client = new Ec2Client([ 'region' => "us-west-1", 'version' => '2016-11-15', 'credentials' => $credentials ]); $ec2_argv = [ 'MaxCount' => 2, 'MinCount' => 2, 'DryRun' => true, 'ImageId' => 'ami-xxxx', 'SubnetId' => 'subnet-xxxx', 'InstanceType' => 'c5.large', ]; $check = $ec2Client->runInstances($ec2_argv); print_r($check);`

Screenshots

Additional context `PHP Fatal error: Uncaught Error: Call to undefined method Error::getResponse() in /data/data/omcs/assets/inc/aws/Aws/Handler/GuzzleV6/GuzzleHandler.php:60 Stack trace:

0 /data/data/omcs/assets/inc/aws/GuzzleHttp/Promise/Promise.php(204): Aws\Handler\GuzzleV6\GuzzleHandler::Aws\Handler\GuzzleV6{closure}(Object(Error))

1 /data/data/omcs/assets/inc/aws/GuzzleHttp/Promise/Promise.php(153): GuzzleHttp\Promise\Promise::callHandler(2, Object(Error), NULL)

2 /data/data/omcs/assets/inc/aws/GuzzleHttp/Promise/TaskQueue.php(48): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure}()

3 /data/data/omcs/assets/inc/aws/GuzzleHttp/Handler/CurlMultiHandler.php(118): GuzzleHttp\Promise\TaskQueue->run()

4 /data/data/omcs/assets/inc/aws/GuzzleHttp/Handler/CurlMultiHandler.php(145): GuzzleHttp\Handler\CurlMultiHandler->tick()

5 /data/data/omcs/assets/inc/aws/GuzzleHttp/Promise/Promise.php(248): GuzzleHttp\Handler\CurlMultiHandler->execute(true)

6 /data/data/omcs/assets/inc/aws/GuzzleHttp/Promise/Promise.php(224): GuzzleHttp\Promise\Pr in /data/data/omcs/assets/inc/aws/Aws/Handler/GuzzleV6/GuzzleHandler.php on line 60

Fatal error: Uncaught Error: Call to undefined method Error::getResponse() in /data/data/omcs/assets/inc/aws/Aws/Handler/GuzzleV6/GuzzleHandler.php:60 Stack trace:

0 /data/data/omcs/assets/inc/aws/GuzzleHttp/Promise/Promise.php(204): Aws\Handler\GuzzleV6\GuzzleHandler::Aws\Handler\GuzzleV6{closure}(Object(Error))

1 /data/data/omcs/assets/inc/aws/GuzzleHttp/Promise/Promise.php(153): GuzzleHttp\Promise\Promise::callHandler(2, Object(Error), NULL)

2 /data/data/omcs/assets/inc/aws/GuzzleHttp/Promise/TaskQueue.php(48): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure}()

3 /data/data/omcs/assets/inc/aws/GuzzleHttp/Handler/CurlMultiHandler.php(118): GuzzleHttp\Promise\TaskQueue->run()

4 /data/data/omcs/assets/inc/aws/GuzzleHttp/Handler/CurlMultiHandler.php(145): GuzzleHttp\Handler\CurlMultiHandler->tick()

5 /data/data/omcs/assets/inc/aws/GuzzleHttp/Promise/Promise.php(248): GuzzleHttp\Handler\CurlMultiHandler->execute(true)

6 /data/data/omcs/assets/inc/aws/GuzzleHttp/Promise/Promise.php(224): GuzzleHttp\Promise\Pr in /data/data/omcs/assets/inc/aws/Aws/Handler/GuzzleV6/GuzzleHandler.php on line 60`

SamRemis commented 3 years ago

Hi @alahoo This usually happens when the service (in this case EC2) is sending an invalid response to the SDK. Could you help me investigate by adding 'debug'=>true to your client constructor and posting the result here? It will print out a long log output, including the raw response from EC2- I believe they would send an XML error.

Please post the raw response here when you get the chance, even if that gives you enough information to solve your problem. It will help me to demonstrate to the company why we need to have more forgiving error parsers that gracefully fail, and prevent problems like this from happening in the future.

Thank you, -Sam

$ec2Client = new Ec2Client([
'region' => "us-west-1",
'version' => '2016-11-15',
'debug' => true
'credentials' => $credentials
]);
alahoo commented 3 years ago

Hi @alahoo This usually happens when the service (in this case EC2) is sending an invalid response to the SDK. Could you help me investigate by adding 'debug'=>true to your client constructor and posting the result here? It will print out a long log output, including the raw response from EC2- I believe they would send an XML error.

Please post the raw response here when you get the chance, even if that gives you enough information to solve your problem. It will help me to demonstrate to the company why we need to have more forgiving error parsers that gracefully fail, and prevent problems like this from happening in the future.

Thank you, -Sam

$ec2Client = new Ec2Client([
'region' => "us-west-1",
'version' => '2016-11-15',
'debug' => true
'credentials' => $credentials
]);

PHP Fatal error: Allowed memory size of 5377097728 bytes exhausted (tried to allocate 3219472384 bytes) in /data/data/omcs/assets/inc/aws/Aws/TraceMiddleware.php on line 261 ll -sh request.log 3.0G -rw-r--r-- 1 root root 3.0G Sep 18 11:57 request.log

Sorry,It's too big

DavidAnderson684 commented 2 years ago

@alahoo I've encountered Error:Call to undefined method Error::getResponse() also, in 3.209.26 (i.e. current release), using the S3 API. According to https://www.php.net/manual/en/class.error.php, there is no such method, so it looks like there is an issue in the SDK here?

SamRemis commented 2 years ago

@DavidAnderson684, on a quick search, I don't believe we have any static calls in the SDK to a getResponse() method, we do have some that look similar in non-static contexts, so I'm wondering if the error you're getting is just being displayed in a confusing way. To help get to the source of this, could you give me the stack trace?

If you have steps to reproduce the issue and/or the raw response from the service which you can obtain using the debug config option mentioned above, that would be helpful as well.

DavidAnderson684 commented 2 years ago

@SamRemis The error is triggered here: https://github.com/aws/aws-sdk-php/blob/bf29058fc637e4949ec42281e9572b9c968b38cc/src/Handler/GuzzleV6/GuzzleHandler.php#L60 . PHP's error message doesn't imply the call was static. But you can see there you're definitely calling getResponse() on an Error object, but there's no such method on that object in the PHP manual.

SamRemis commented 2 years ago

Right, I can see where that issue would happen. Maybe it was supposed to be getMessage or something, I'll look into the commit history and get a patch out. Do you have any info on what error was actually thrown?

DavidAnderson684 commented 2 years ago

@SamRemis Unfortunately I have no more than the error message - it was sent to us by a user from their logs.

SamRemis commented 2 years ago

@DavidAnderson684, Thanks for your help here! Will be nice to close out this issue. I just made a PR that should fix this once it's merged

github-actions[bot] commented 2 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.