diff --git a/.changes/nextrelease/s3-region-fix.json b/.changes/nextrelease/s3-region-fix.json new file mode 100644 index 0000000000..3f7544de1b --- /dev/null +++ b/.changes/nextrelease/s3-region-fix.json @@ -0,0 +1,7 @@ +[ + { + "type": "bugfix", + "category": "S3", + "description": "Fixes warning in S3 client when region is not provided in constructor" + } +] diff --git a/src/S3/S3Client.php b/src/S3/S3Client.php index da0e1dfe39..88de7473f7 100644 --- a/src/S3/S3Client.php +++ b/src/S3/S3Client.php @@ -801,9 +801,18 @@ private function processEndpointV2Model() */ private function addBuiltIns($args) { - if ($args['region'] !== 'us-east-1') { + if (isset($args['region']) + && $args['region'] !== 'us-east-1' + ) { + return false; + } + + if (!isset($args['region']) + && ConfigurationResolver::resolve('region', '', 'string') !== 'us-east-1' + ) { return false; } + $key = 'AWS::S3::UseGlobalEndpoint'; $result = $args['s3_us_east_1_regional_endpoint'] instanceof \Closure ? $args['s3_us_east_1_regional_endpoint']()->wait() : $args['s3_us_east_1_regional_endpoint']; diff --git a/tests/S3/S3ClientTest.php b/tests/S3/S3ClientTest.php index 9b4f0d64e3..7eddeebfc6 100644 --- a/tests/S3/S3ClientTest.php +++ b/tests/S3/S3ClientTest.php @@ -1,7 +1,6 @@ getClientBuiltIns(); + //The UseGlobalEndpoint builtin should be set by default if + //the region provided is us-east-1. + $this->assertEquals($expected, isset($builtIns['AWS::S3::UseGlobalEndpoint'])); + + //When the UseGlobalEndpoint builtin is set (i.e. us-east-1 is the region) + // the default value should be `true`, unless `s3_us_east_1_regional_endpoint` + // is set to `regional`. + if ($expected) { + $this->assertEquals($expected, $builtIns['AWS::S3::UseGlobalEndpoint']); + } + + putenv('AWS_REGION='); + } + + public function builtinRegionProvider() + { + return [ + ['us-east-1' , true], + ['us-west-2', false] + ]; + } }