Missing required client configuration options: region

15,631

Solution 1

I had the same problem and I needed to clear my config cache to fix it.

$ artisan config:clear

Solution 2

Set region explicitly when creating s3 client instead of relying on defaults.

use Aws\Credentials\Credentials;
use Aws\S3\S3Client;

$result = $stsClient->getSessionToken();

$credentials = new Credentials(
    $result['Credentials']['AccessKeyId'],
    $result['Credentials']['SecretAccessKey'],
    $result['Credentials']['SessionToken']
);

$s3Client = new S3Client([
    'version'     => '2006-03-01',
    'region'      => 'us-west-2',
    'credentials' => $credentials
]);

Solution 3

Check .env file variables are matching with filesystems.php

's3' => [
            'driver' => 's3',
            'key' => env('S3_KEY'),
            'secret' => env('S3_SECRET'),
            'region' => env('S3_REGION'),
            'bucket' => env('S3_BUCKET'),
        ],
Share:
15,631
EmptyData
Author by

EmptyData

Give a man a fish, you feed him for a day; teach a man to fish, you feed him for life. "Creative minds are rarely tidy" ;)

Updated on July 13, 2022

Comments

  • EmptyData
    EmptyData almost 2 years

    I am trying to check bucket existence on Amazon S3 using below code:

    $credentials = new Aws\Common\Credentials\Credentials($creds['access_key_id'], $creds['secret_access_key']);
    $client = Aws\S3\S3Client::factory(array( 'credentials' => $credentials ) );
    if( ! $client->doesBucketExist($creds['bucket']) ) {
        throw new Exception("Bucket (" . $creds['bucket'] . ") does not exist.");
    }
    

    It is working on localhost (wamp) but when I tried this on server it is not working. I am getting following error:

    Missing required client configuration options: region: (string) A "region" configuration value is required for the "s3" service (e.g., "us-west-2"). A list of available public regions and endpoints can be found at http://docs.aws.amazon.com/general/latest/gr/rande.html. version: (string) A "version" configuration value is required. Specifying a version constraint ensures that your code will not be affected by a breaking change made to the service. For example, when using Amazon S3, you can lock your API version to "2006-03-01". Your build of the SDK has the following version(s) of "s3": * "2006-03-01" You may provide "latest" to the "version" configuration value to utilize the most recent available API version that your client's API provider can find. Note: Using 'latest' in a production application is not recommended. A list of available API versions can be found on each client's API documentation page: http://docs.aws.amazon.com/aws-sdk-php/v3/api/index.html. If you are unable to load a specific API version, then you may need to update your copy of the SDK.

    I don't know why it is not working on server but same code is working on localhost.

  • EmptyData
    EmptyData almost 7 years
    why do I need to provide Aws\Credentials\Credentials instead of Aws\Common\Credentials\Credentials
  • RaGe
    RaGe almost 7 years
    Depends on aws-sdk-php version you use. 2.8 vs 3.0 Common went away. See 1 vs 2
  • Chris
    Chris about 5 years
    Welcome to Stack Overflow! Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem, and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you've made.