{"action":"created","issue":{"url":"https://api.github.com/repos/aws/aws-sdk-php/issues/582","labels_url":"https://api.github.com/repos/aws/aws-sdk-php/issues/582/labels{/name}","comments_url":"https://api.github.com/repos/aws/aws-sdk-php/issues/582/comments","events_url":"https://api.github.com/repos/aws/aws-sdk-php/issues/582/events","html_url":"https://github.com/aws/aws-sdk-php/issues/582","id":78226796,"number":582,"title":"Amazon S3 Set Signature If V4","user":{"login":"sobytes","id":2689776,"avatar_url":"https://avatars.githubusercontent.com/u/2689776?v=3","gravatar_id":"","url":"https://api.github.com/users/sobytes","html_url":"https://github.com/sobytes","followers_url":"https://api.github.com/users/sobytes/followers","following_url":"https://api.github.com/users/sobytes/following{/other_user}","gists_url":"https://api.github.com/users/sobytes/gists{/gist_id}","starred_url":"https://api.github.com/users/sobytes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sobytes/subscriptions","organizations_url":"https://api.github.com/users/sobytes/orgs","repos_url":"https://api.github.com/users/sobytes/repos","events_url":"https://api.github.com/users/sobytes/events{/privacy}","received_events_url":"https://api.github.com/users/sobytes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-05-19T19:45:50Z","updated_at":"2015-05-19T20:22:50Z","closed_at":null,"body":"Having the following issues, i am calling this function\r\n~~~\r\n$bucket = 'bucket';\r\n$client = S3Client::factory(array(\r\n    'key'    => 'key',\r\n    'secret' => 'secret'\r\n));\r\n\r\ntry\r\n{\r\n\r\n    //Check Bucket Region Important\r\n    $result = $client->getBucketLocation(array(\r\n        // Bucket is required\r\n        'Bucket' => $bucket\r\n    ))->toArray();\r\n\r\n    $region = $result['Location'];\r\n\r\n    if(!empty($region)){\r\n        if($region != 'EU'){\r\n            $client->setRegion($region);\r\n        }\r\n    }\r\n\r\n    $iterator = $client -> listObjects(array(\r\n        'Bucket' => $bucket,\r\n        'Delimiter' => '/'\r\n    ));\r\n}\r\ncatch (Exception $e)\r\n{\r\n    echo json_encode(array(\"error\" => $e -> getMessage()));\r\n}\r\n\r\ndie();\r\n~~~\r\n\r\nWhich is outputting.\r\n\r\n{\"error\":\"The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.\"}\r\n\r\nHow do i get the signature and then set it to v4 if its in the region eu-central-1\r\n\r\nI cant set it in the factory call because it maybe different everytime?\r\n\r\nAny help thanks"},"comment":{"url":"https://api.github.com/repos/aws/aws-sdk-php/issues/comments/103658365","html_url":"https://github.com/aws/aws-sdk-php/issues/582#issuecomment-103658365","issue_url":"https://api.github.com/repos/aws/aws-sdk-php/issues/582","id":103658365,"user":{"login":"mtdowling","id":190930,"avatar_url":"https://avatars.githubusercontent.com/u/190930?v=3","gravatar_id":"","url":"https://api.github.com/users/mtdowling","html_url":"https://github.com/mtdowling","followers_url":"https://api.github.com/users/mtdowling/followers","following_url":"https://api.github.com/users/mtdowling/following{/other_user}","gists_url":"https://api.github.com/users/mtdowling/gists{/gist_id}","starred_url":"https://api.github.com/users/mtdowling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtdowling/subscriptions","organizations_url":"https://api.github.com/users/mtdowling/orgs","repos_url":"https://api.github.com/users/mtdowling/repos","events_url":"https://api.github.com/users/mtdowling/events{/privacy}","received_events_url":"https://api.github.com/users/mtdowling/received_events","type":"User","site_admin":false},"created_at":"2015-05-19T20:22:50Z","updated_at":"2015-05-19T20:22:50Z","body":"Amazon S3 regions have recently become \"region aware\", meaning you actually need to know the region you are contacting before you send requests. This limitation was introduced because some regions require signature version 4. In the past, you could send a request a \"s3.amazonaws.com\" and it would mostly \"just work\" thanks to CNAMEs or redirects taking you to the correct regionalized bucket. However, with the addition of sigv4 only regions (e.g., \"eu-central-1\"), it is now not possible to rely on this behavior as sigv4 regions must be signed explicitly for the region you are contacting (for canonicalizing the signature). \r\n\r\nThe good news is that you can call `getBucketLocation` against any region endpoint and it will give you the actual region a bucket is stored in. You then need to use a client that has been configured to use that region when sending requests to those buckets. There are various ways you could achieve this; one thing that comes to mind is decorating S3Client, getting the region of a bucket before sending requests, using a client that is scoped for the given region, and returning the result. You could cache previously created clients to avoid having to create clients over and over."}}