aws / aws-sdk-php

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

S3 PutObject doesn't work on VPN #2913

Closed spencerchubb closed 6 months ago

spencerchubb commented 7 months ago

Describe the bug

I apologize if this is the wrong place to ask.

function uploadToS3($bucket, $key, $filename) {
    try {
        $credentialProvider = CredentialProvider::ini();
        $credentialProvider = CredentialProvider::memoize($credentialProvider); // Cache to avoid loading every time.

        $s3 = new S3Client([
            'version' => '2006-03-01',
            'region' => 'us-east-1',
            'credentials' => $credentialProvider,
        ]);
        $result = $s3->putObject([
            'Bucket' => $bucket,
            'Key' => $key,
            'SourceFile' => $filename,
        ]);

        return NULL;
    } catch (S3Exception $e) {
        return $e->getMessage();
    }
}

This code works perfectly fine without the VPN, but fails with the vpn. Here is the error message:

"Error executing "PutObject" on "https://{bucket}.s3.amazonaws.com/{key}"; AWS HTTP error: Error creating resource: [message] fopen(): php_network_getaddresses: getaddrinfo for {bucket}.s3.amazonaws.com failed: Name or service not known
[file] /var/www/html/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php
[line] 324
[message] fopen(https://{bucket}.s3.amazonaws.com/{key}): Failed to open stream: php_network_getaddresses: getaddrinfo for {bucket}.s3.amazonaws.com failed: Name or service not known
[file] /var/www/html/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php
[line] 324"

Expected Behavior

Work with and without vpn

Current Behavior

Only works without vpn

Reproduction Steps

See above

Possible Solution

No response

Additional Information/Context

No response

SDK version used

^3.33

Environment details (Version of PHP (php -v)? OS name and version, etc.)

PHP 8.1.2-1ubuntu2.14 (cli) (built: Aug 18 2023 11:41:11) (NTS)Copyright (c) The PHP Group Zend Engine v4.1.2, Copyright (c) Zend Technologies with Zend OPcache v8.1.2-1ubuntu2.14, Copyright (c), by Zend Technologies

stobrien89 commented 7 months ago

Hi @spencerchubb,

Sorry to hear about the issues. Could you provide some debug log output so we can get a better idea of what's happening here? You can enable debug logging by adding 'debug' => true to your client configuration. Please be sure to obscure any sensitive information like credentials and account numbers.