AWS SDK for PHP 3.x
  • Namespace
  • Class

Namespaces

  • Aws
    • Acm
      • Exception
    • ACMPCA
      • Exception
    • AlexaForBusiness
      • Exception
    • Amplify
      • Exception
    • Api
      • ErrorParser
      • Parser
        • Exception
      • Serializer
    • ApiGateway
      • Exception
    • ApiGatewayManagementApi
      • Exception
    • ApiGatewayV2
      • Exception
    • ApplicationAutoScaling
      • Exception
    • ApplicationDiscoveryService
      • Exception
    • AppMesh
      • Exception
    • Appstream
      • Exception
    • AppSync
      • Exception
    • Athena
      • Exception
    • AutoScaling
      • Exception
    • AutoScalingPlans
      • Exception
    • Backup
      • Exception
    • Batch
      • Exception
    • Budgets
      • Exception
    • Chime
      • Exception
    • ClientSideMonitoring
      • Exception
    • Cloud9
      • Exception
    • CloudDirectory
      • Exception
    • CloudFormation
      • Exception
    • CloudFront
      • Exception
    • CloudHsm
      • Exception
    • CloudHSMV2
      • Exception
    • CloudSearch
      • Exception
    • CloudSearchDomain
      • Exception
    • CloudTrail
      • Exception
    • CloudWatch
      • Exception
    • CloudWatchEvents
      • Exception
    • CloudWatchLogs
      • Exception
    • CodeBuild
      • Exception
    • CodeCommit
      • Exception
    • CodeDeploy
      • Exception
    • CodePipeline
      • Exception
    • CodeStar
      • Exception
    • CognitoIdentity
      • Exception
    • CognitoIdentityProvider
      • Exception
    • CognitoSync
      • Exception
    • Comprehend
      • Exception
    • ComprehendMedical
      • Exception
    • ConfigService
      • Exception
    • Connect
      • Exception
    • CostandUsageReportService
      • Exception
    • CostExplorer
      • Exception
    • Credentials
    • Crypto
      • Cipher
    • DatabaseMigrationService
      • Exception
    • DataPipeline
      • Exception
    • DataSync
      • Exception
    • DAX
      • Exception
    • DeviceFarm
      • Exception
    • DirectConnect
      • Exception
    • DirectoryService
      • Exception
    • DLM
      • Exception
    • DocDB
      • Exception
    • DynamoDb
      • Exception
    • DynamoDbStreams
      • Exception
    • Ec2
      • Exception
    • Ecr
      • Exception
    • Ecs
      • Exception
    • Efs
      • Exception
    • EKS
      • Exception
    • ElastiCache
      • Exception
    • ElasticBeanstalk
      • Exception
    • ElasticLoadBalancing
      • Exception
    • ElasticLoadBalancingV2
      • Exception
    • ElasticsearchService
      • Exception
    • ElasticTranscoder
      • Exception
    • Emr
      • Exception
    • Endpoint
    • EndpointDiscovery
      • Exception
    • Exception
    • Firehose
      • Exception
    • FMS
      • Exception
    • FSx
      • Exception
    • GameLift
      • Exception
    • Glacier
      • Exception
    • GlobalAccelerator
      • Exception
    • Glue
      • Exception
    • Greengrass
      • Exception
    • GuardDuty
      • Exception
    • Handler
      • GuzzleV5
      • GuzzleV6
    • Health
      • Exception
    • Iam
      • Exception
    • ImportExport
      • Exception
    • Inspector
      • Exception
    • Iot
      • Exception
    • IoT1ClickDevicesService
      • Exception
    • IoT1ClickProjects
      • Exception
    • IoTAnalytics
      • Exception
    • IotDataPlane
      • Exception
    • IoTJobsDataPlane
      • Exception
    • Kafka
      • Exception
    • Kinesis
      • Exception
    • KinesisAnalytics
      • Exception
    • KinesisAnalyticsV2
      • Exception
    • KinesisVideo
      • Exception
    • KinesisVideoArchivedMedia
      • Exception
    • KinesisVideoMedia
      • Exception
    • Kms
      • Exception
    • Lambda
      • Exception
    • LexModelBuildingService
      • Exception
    • LexRuntimeService
      • Exception
    • LicenseManager
      • Exception
    • Lightsail
      • Exception
    • MachineLearning
      • Exception
    • Macie
      • Exception
    • MarketplaceCommerceAnalytics
      • Exception
    • MarketplaceEntitlementService
      • Exception
    • MarketplaceMetering
      • Exception
    • MediaConnect
      • Exception
    • MediaConvert
      • Exception
    • MediaLive
      • Exception
    • MediaPackage
      • Exception
    • MediaStore
      • Exception
    • MediaStoreData
      • Exception
    • MediaTailor
      • Exception
    • MigrationHub
      • Exception
    • Mobile
      • Exception
    • MQ
      • Exception
    • MTurk
      • Exception
    • Multipart
    • Neptune
      • Exception
    • OpsWorks
      • Exception
    • OpsWorksCM
      • Exception
    • Organizations
      • Exception
    • PI
      • Exception
    • Pinpoint
      • Exception
    • PinpointEmail
      • Exception
    • PinpointSMSVoice
      • Exception
    • Polly
      • Exception
    • Pricing
      • Exception
    • QuickSight
      • Exception
    • RAM
      • Exception
    • Rds
      • Exception
    • RDSDataService
      • Exception
    • Redshift
      • Exception
    • Rekognition
      • Exception
    • ResourceGroups
      • Exception
    • ResourceGroupsTaggingAPI
      • Exception
    • RoboMaker
      • Exception
    • Route53
      • Exception
    • Route53Domains
      • Exception
    • Route53Resolver
      • Exception
    • S3
      • Crypto
      • Exception
    • S3Control
      • Exception
    • SageMaker
      • Exception
    • SageMakerRuntime
      • Exception
    • SecretsManager
      • Exception
    • SecurityHub
      • Exception
    • ServerlessApplicationRepository
      • Exception
    • ServiceCatalog
      • Exception
    • ServiceDiscovery
      • Exception
    • Ses
      • Exception
    • Sfn
      • Exception
    • Shield
      • Exception
    • Signature
    • signer
      • Exception
    • Sms
      • Exception
    • SnowBall
      • Exception
    • Sns
      • Exception
    • Sqs
      • Exception
    • Ssm
      • Exception
    • StorageGateway
      • Exception
    • Sts
      • Exception
    • Support
      • Exception
    • Swf
      • Exception
    • TranscribeService
      • Exception
    • Transfer
      • Exception
    • Translate
      • Exception
    • Waf
      • Exception
    • WafRegional
      • Exception
    • WorkDocs
      • Exception
    • WorkLink
      • Exception
    • WorkMail
      • Exception
    • WorkSpaces
      • Exception
    • XRay
      • Exception
  • GuzzleHttp
    • Promise
    • Psr7
  • Psr
    • Http
      • Message

Classes

  • AssumeRoleCredentialProvider
  • CredentialProvider
  • Credentials
  • EcsCredentialProvider
  • InstanceProfileProvider

Interfaces

  • CredentialsInterface

Class CredentialProvider

Credential providers are functions that accept no arguments and return a promise that is fulfilled with an Aws\Credentials\CredentialsInterface or rejected with an 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 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 Summary

  • static defaultProvider ( array $config = [] )

    Create a default credential provider that first checks for environment variables, then checks for the "default" profile in ~/.aws/credentials, then checks for "profile default" profile in ~/.aws/config (which is the default profile of AWS CLI), then tries to make a GET Request to fetch credentials if Ecs environment variable is presented, and finally checks for EC2 instance profile credentials.

  • static fromCredentials ( Aws\Credentials\CredentialsInterface $creds )

    Create a credential provider function from a set of static credentials.

  • static chain ( )

    Creates an aggregate credentials provider that invokes the provided variadic providers one after the other until a provider returns credentials.

  • static memoize ( callable $provider )

    Wraps a credential provider and caches previously provided credentials.

  • static cache ( callable $provider, Aws\CacheInterface $cache, string|null $cacheKey = null )

    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.

  • static env ( )

    Provider that creates credentials from environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN.

  • static instanceProfile ( array $config = [] )

    Credential provider that creates credentials using instance profile credentials.

  • static ecsCredentials ( array $config = [] )

    Credential provider that creates credentials using ecs credentials by a GET request, whose uri is specified by environment variable

  • static assumeRole ( array $config = [] )

    Credential provider that creates credentials using assume role

  • static ini ( string|null $profile = null, string|null $filename = null )

    Credentials provider that creates credentials using an ini file stored in the current user's home directory.

Methods Details

static callable defaultProvider ( array $config = [] )

Create a default credential provider that first checks for environment variables, then checks for the "default" profile in ~/.aws/credentials, then checks for "profile default" profile in ~/.aws/config (which is the default profile of AWS CLI), then tries to make a GET Request to fetch credentials if Ecs environment variable is presented, and finally checks for EC2 instance profile credentials.

This provider is automatically wrapped in a memoize function that caches previously provided credentials.

Parameters

array $config = []

Optional array of ecs/instance profile credentials provider options.

Returns

callable

static callable fromCredentials ( Aws\Credentials\CredentialsInterface $creds )

Create a credential provider function from a set of static credentials.

Parameters

Aws\Credentials\CredentialsInterface $creds

Returns

callable

static callable chain ( )

Creates an aggregate credentials provider that invokes the provided variadic providers one after the other until a provider returns credentials.

Returns

callable

static callable memoize ( callable $provider )

Wraps a credential provider and caches previously provided credentials.

Ensures that cached credentials are refreshed when they expire.

Parameters

callable $provider Credentials provider function to wrap.

Returns

callable

static callable cache ( callable $provider, Aws\CacheInterface $cache, string|null $cacheKey = null )

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.

Defaults to using a simple file-based cache when none provided.

Parameters

callable $provider Credentials provider function to wrap
Aws\CacheInterface $cache Cache to store credentials
string|null $cacheKey = null (optional) Cache key to use

Returns

callable

static callable env ( )

Provider that creates credentials from environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN.

Returns

callable

static Aws\Credentials\InstanceProfileProvider instanceProfile ( array $config = [] )

Credential provider that creates credentials using instance profile credentials.

Parameters

array $config = [] Array of configuration data.

Returns

Aws\Credentials\InstanceProfileProvider

See

Aws\Credentials\InstanceProfileProvider for $config details.

static Aws\Credentials\EcsCredentialProvider ecsCredentials ( array $config = [] )

Credential provider that creates credentials using ecs credentials by a GET request, whose uri is specified by environment variable

Parameters

array $config = [] Array of configuration data.

Returns

Aws\Credentials\EcsCredentialProvider

See

Aws\Credentials\EcsCredentialProvider for $config details.

static callable assumeRole ( array $config = [] )

Credential provider that creates credentials using assume role

Parameters

array $config = [] Array of configuration data

Returns

callable

See

Aws\Credentials\AssumeRoleCredentialProvider for $config details.

static callable ini ( string|null $profile = null, string|null $filename = null )

Credentials provider that creates credentials using an ini file stored in the current user's home directory.

Parameters

string|null $profile = null

Profile to use. If not specified will use the "default" profile in "~/.aws/credentials".

string|null $filename = null

If provided, uses a custom filename rather than looking in the home directory.

Returns

callable

Constants summary

string ENV_KEY
# 'AWS_ACCESS_KEY_ID'
string ENV_SECRET
# 'AWS_SECRET_ACCESS_KEY'
string ENV_SESSION
# 'AWS_SESSION_TOKEN'
string ENV_PROFILE
# 'AWS_PROFILE'
AWS SDK for PHP 3.x API documentation generated by ApiGen