Aws-sdk-php: Duplicated scheme "http" in Uri by the S3EndpointMiddleware

Created on 3 Feb 2021  路  25Comments  路  Source: aws/aws-sdk-php

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

Describe the bug
When the endpoint option is set and path style endpoints are set to true, the S3EndpointMiddleware produces a Uri with both the scheme and the host in the host property of the Uri. This causes issues when the Uri get's to Guzzle as Guzzle replaces the blank scheme with 'http', duplicating 'http' in the final Uri.

Version of AWS SDK for PHP?
v3.173.0

Version of PHP (php -v)?
na

To Reproduce (observed behavior)
We encountered this bug while using the sdk configured via the Symfony aws bundle, with the options for path style endpoints set to true and custom endpoints for localstack.

aws:
  S3:
    use_path_style_endpoint: true
    endpoint: http://my-endpoint:123

Expected behavior
Here is a failing unit test showing what I thought the expected behavior should be.

    public function testApplyingEndpointWhenEndpointOptionAndPathStyleAreSet()
    {
        $nextHandler = function ($command, Request $request){
            $uri = $request->getUri();
            $this->assertEquals($expectedHost = 'my-endpoint', $uri->getHost());
            $this->assertEquals($expectedScheme = 'http', $uri->getScheme());
        };
        $command = new Command('CreateBucket', ['Bucket' => 'abc']);
        $middleware = new S3EndpointMiddleware( $nextHandler, 'us-west-2', [
            'endpoint' => 'http://my-endpoint:123',
            'path_style' => true
        ]);
        $requestUri = new Uri('http://my-endpoint:123');
        $request = new Request('PUT',$requestUri);
        $middleware($command, $request);
    }

Additional context
I'm not the most familiar with the implications of path style endpoints. I've read a bit about the plan for them to be deprecated. So sorry in advance if there is something I am missing and this is not an issue.

bug needs-triage

Most helpful comment

@SamRemis I can confirm that downgrading to 3.172.4 works for me.

All 25 comments

Same here. The SDK works fine in 3.172.4

I think it is related to my error too.

Aws\S3\Exception\S3Exception: Error executing "PutObject" on "//http://127.0.0.1:9000"; AWS HTTP error: cURL error 6: Could not resolve host: http (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://http://127.0.0.1:9000

I downgrade to version 3.172.0

Same error here too.

"Error executing "PutObject" on "//http://object-storage:9000/";

@aldenw This is certainly an issue, and thanks for bringing it to my attention. I'll take a look right away

@SamRemis I took a naive shot at making a pull request for it here.

@aldenw Thank you very much, that will help me get this public much more quickly :) will go review it now

The fix from @aldenw is merged, and appears to have fixed the issue from my machine. Can anyone else confirm the fix is out to them as well?

@SamRemis This has not fixed the issue for me. What I have now is the bucket name before the endpoint.

@stevepop Thank you, I will look into that too and try to get another urgent fix out

@stevepop, just reverted a feature that I believe caused the issue- could you let me know if it's fixed for you?

@SamRemis I will try it now and let you know 馃憤

Version 3.173.0 has the problem
Version 3.173.1 seems to be working correctly

@mikedodd Thank you for the confirmation

@SamRemis Unfortunately 3.173.1 does not work for me. Just to let you know that I am using league/flysystem-aws-s3-v3 which depends on this library. I will try 3.173.0 and see if that works.

@stevepop, please try one of the confirmed earlier versions - 3.172.*

@SamRemis I can confirm that downgrading to 3.172.4 works for me.

@stevepop, depending on how you're integrating the SDK with your project, the fix earlier may not have worked due to the version number. The fix I pushed was in 3.173.2

@SamRemis I am happy to try that version and feed you back. I can always go back to the version that works if this one doesn't.

@SamRemis I can confirm that this fixes the issue for me.

@stevepop it's alright, just wanted to let you know. I'm working on a more permanent solution for tomorrow's release

@SamRemis I can confirm that 3.173.2 works! 馃憤

@NickJorens and @stevepop, Thank you so much for your help in confirming the issue is resolved

@NickJorens and @stevepop, Thank you so much for your help in confirming the issue is resolved

Thanks for getting this resolved so quickly!

I can confirm that this issue has resolved at 3.173.2. Thanks!

鈿狅笍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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Intrepidity picture Intrepidity  路  4Comments

chiukit picture chiukit  路  4Comments

sm2017 picture sm2017  路  4Comments

andy3rdworld picture andy3rdworld  路  4Comments

sh-ogawa picture sh-ogawa  路  4Comments