Class Aws\Credentials\CredentialProvider

Credential providers are functions that accept no arguments and return a promise that is fulfilled with an {@see \Aws\Credentials\CredentialsInterface} or rejected with an {@see \Aws\Exception\CredentialsException}.

use Aws\Credentials\CredentialProvider; $provider = CredentialProvider::defaultProvider(); // Returns a CredentialsInterface or throws. $creds = $provider()->wait();

Credential providers can be composed to create credentials using conditional logic that can create different credentials in different environments. You can compose multiple providers into a single provider using {@see Aws\Credentials\CredentialProvider::chain}. This function accepts providers as variadic arguments and returns a new function that will invoke each provider until a successful set of credentials is returned.

// First try an INI file at this location. $a = CredentialProvider::ini(null, '/path/to/file.ini'); // Then try an INI file at this location. $b = CredentialProvider::ini(null, '/path/to/other-file.ini'); // Then try loading from environment variables. $c = CredentialProvider::env(); // Combine the three providers together. $composed = CredentialProvider::chain($a, $b, $c); // Returns a promise that is fulfilled with credentials or throws. $promise = $composed(); // Wait on the credentials to resolve. $creds = $promise->wait();
Methods
Constants