Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error in guzzle when i try to create an invalidation #2349

Closed
3 tasks done
mikiamomik opened this issue Nov 8, 2021 · 5 comments
Closed
3 tasks done

Fatal error in guzzle when i try to create an invalidation #2349

mikiamomik opened this issue Nov 8, 2021 · 5 comments
Assignees
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@mikiamomik
Copy link

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

Describe the bug
When I try to createInvalidation it return a fatal error in guzzle
Fatal error: Uncaught Error: Call to undefined method TypeError::getResponse()
in /vendor/aws/aws-sdk-php/src/Handler/GuzzleV6/GuzzleHandler.php on line 60

Version of AWS SDK for PHP?
aws/aws-crt-php v1.0.2 AWS Common Runtime for PHP
aws/aws-sdk-php 3.200.1 AWS SDK for PHP - Use Amazon Web Services in your PHP project
guzzlehttp/guzzle 7.4.0 Guzzle is a PHP HTTP client library
guzzlehttp/promises 1.5.1 Guzzle promises library
guzzlehttp/psr7 1.8.3 PSR-7 message implementation that also provides common utility methods

Version of PHP (php -v)?
PHP 7.4.25 (cli) (built: Oct 22 2021 12:34:33) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.25, Copyright (c), by Zend Technologies

This is my code

use Aws\Credentials\Credentials;
use Aws\Sdk;
use Aws\CloudFront\CloudFrontClient; 
use Aws\Exception\AwsException;
.....

public function purge_cloudfront_invalidation_flush($paths)
{
    if (empty($paths)) {
        return false;
    }
    $cf = $this->get_cloudfront_infos();

    if (!isset($cf['Enabled']) || (bool) $cf['Enabled'] === false) {
        return false;
    }
    $distributionId = $cf['DistributionId'];
    $callerReference = $distributionId . "-" . date('YmdHis');
    $quantity = count($paths);

    $credentialsKey = $cf['CredentialsKey'];
    $credentialsSecret = $cf['CredentialsSecret'];

    $cloudFrontClient = (new Sdk([
        'region' => $cf['ClientRegion'],
        'version' => $cf['ClientVersion'],
        'credentials' => new Credentials($credentialsKey, $credentialsSecret),
    ]))->createCloudFront();

    return $this->CloudfrontCreateInvalidation($cloudFrontClient, $distributionId, $callerReference, $paths, $quantity);
}

private function CloudfrontCreateInvalidation($cloudFrontClient, $distributionId, $callerReference, $paths, $quantity)
{
    try {
        $result = $cloudFrontClient->createInvalidation([
            'DistributionId' => $distributionId,
            'InvalidationBatch' => [
                'CallerReference' => $callerReference,
                'Paths' => [
                    'Items' => $paths,
                    'Quantity' => $quantity,
                ],
            ],
        ]);
        
        $message = '';

        if (isset($result['Location'])) {
            $message = 'The invalidation location is: ' .
                $result['Location'];
        }

        $message .= ' and the effective URI is ' .
            $result['@metadata']['effectiveUri'] . '.';

        return $message;
    } catch (AwsException $e) {
        return 'Error: ' . $e->getAwsErrorMessage();
    } catch (Exception $e) {
        return 'Error: ' . $e->getMessage();
    }
}

When CloudfrontCreateInvalidation is launched... fatal error appears...
I do not understand why!

@mikiamomik mikiamomik added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 8, 2021
@mikiamomik
Copy link
Author

I think the problem is guzzlehttp/guzzle 7.4.0. With guzzle 7.3.0 it seems to work.
I use Wordpress plugin Cloudflare. When I update it to version 4.7.0 (instead of 4.6.0), it force guzzle to 7.4.0

@stobrien89 stobrien89 added guidance Question that needs advice or information. and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 4, 2022
@stobrien89
Copy link
Member

Hi @mikiamomik,

Apologies for the delayed response. I see this may have been resolved on the cloudflare-wordpress side via cloudflare/Cloudflare-WordPress#446. Can you confirm?

@stobrien89 stobrien89 added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Apr 4, 2022
@github-actions
Copy link

This issue has not recieved a response in 1 week. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Apr 10, 2022
@stobrien89
Copy link
Member

Hi @mikiamomik,

Closing for now, but please let us know if you're still having issues.

@github-actions
Copy link

⚠️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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants