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();
Mostrar archivo
Open project: aws/aws-sdk-php
Class Usage Examples
Method | Description | |
---|---|---|
cache ( callable $provider, Aws\CacheInterface $cache, string | null $cacheKey = null ) : callable | Wraps a credential provider and saves provided credentials in an instance of Aws\CacheInterface. Forwards calls when no credentials found in cache and updates cache with the results. | |
chain ( ) : callable | Creates an aggregate credentials provider that invokes the provided variadic providers one after the other until a provider returns credentials. | |
defaultProvider ( array $config = [] ) : callable | Create a default credential provider that first checks for environment variables, then checks for the "default" profile in ~/.aws/credentials, then tries to make GET Request to fetch credentials if Ecs environment variable is presented, and finally checks for EC2 instance profile credentials. | |
ecsCredentials ( array $config = [] ) : |
Credential provider that creates credentials using ecs credentials by a GET request, whose uri is specified by environment variable | |
env ( ) : callable | Provider that creates credentials from environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN. | |
fromCredentials ( Aws\Credentials\CredentialsInterface $creds ) : callable | Create a credential provider function from a set of static credentials. | |
ini ( string | null $profile = null, string | null $filename = null ) : callable | Credentials provider that creates credentials using an ini file stored in the current user's home directory. | |
instanceProfile ( array $config = [] ) : Aws\Credentials\InstanceProfileProvider | Credential provider that creates credentials using instance profile credentials. | |
memoize ( callable $provider ) : callable | Wraps a credential provider and caches previously provided credentials. |
Method | Description | |
---|---|---|
getHomeDir ( ) : null | string | Gets the environment's HOME directory if available. | |
reject ( $msg ) |
public static defaultProvider ( array $config = [] ) : callable | ||
$config | array | Optional array of instance profile credentials provider options. |
return | callable |
public static ecsCredentials ( array $config = [] ) : |
||
$config | array | Array of configuration data. |
return |
public static fromCredentials ( Aws\Credentials\CredentialsInterface $creds ) : callable | ||
$creds | Aws\Credentials\CredentialsInterface | |
return | callable |
public static ini ( string | null $profile = null, string | null $filename = null ) : callable | ||
$profile | string | null | Profile to use. If not specified will use the "default" profile. |
$filename | string | null | If provided, uses a custom filename rather than looking in the home directory for the |
return | callable |
public static instanceProfile ( array $config = [] ) : Aws\Credentials\InstanceProfileProvider | ||
$config | array | Array of configuration data. |
return | Aws\Credentials\InstanceProfileProvider |