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 | ||
---|---|---|
public
static
|
defaultProvider(array $config = []): callable
|
# |
public
static
|
fromCredentials(CredentialsInterface $creds): callable
|
# |
public
static
|
chain(): callable
|
# |
public
static
|
memoize(callable $provider): callable
|
# |
public
static
|
cache(callable $provider, CacheInterface $cache, string|null $cacheKey = null): callable
|
# |
public
static
|
env(): callable
|
# |
public
static
|
instanceProfile(array $config = []): InstanceProfileProvider
|
# |
public
static
|
sso($ssoProfileName = 'default', $filename = null, $config = []): callable
|
# |
public
static
|
ecsCredentials(array $config = []): EcsCredentialProvider
|
# |
public
static
|
assumeRole(array $config = []): callable
|
# |
public
static
|
assumeRoleWithWebIdentityCredentialProvider(array $config = []): callable
|
# |
public
static
|
ini(string|null $profile = null, string|null $filename = null, array|null $config = []): callable
|
# |
public
static
|
process(string|null $profile = null, string|null $filename = null): callable
|
# |
public
static
|
getCredentialsFromSource($profileName = '', $filename = '', $config = [])
|
# |
public
static
|
shouldUseEcs(): boolean
|
# |
Constants | ||
---|---|---|
public
|
ENV_ARN = 'AWS_ROLE_ARN'
|
# |
public
|
ENV_KEY = 'AWS_ACCESS_KEY_ID'
|
# |
public
|
ENV_PROFILE = 'AWS_PROFILE'
|
# |
public
|
ENV_ROLE_SESSION_NAME = 'AWS_ROLE_SESSION_NAME'
|
# |
public
|
ENV_SECRET = 'AWS_SECRET_ACCESS_KEY'
|
# |
public
|
ENV_ACCOUNT_ID = 'AWS_ACCOUNT_ID'
|
# |
public
|
ENV_SESSION = 'AWS_SESSION_TOKEN'
|
# |
public
|
ENV_TOKEN_FILE = 'AWS_WEB_IDENTITY_TOKEN_FILE'
|
# |
public
|
ENV_SHARED_CREDENTIALS_FILE = 'AWS_SHARED_CREDENTIALS_FILE'
|
# |