Sts client

This page contains examples with the Sts client. See the client introduction for a more detailed description how to use a client. You may also want to consider the authentication documentation to understand the many ways you can authenticate with AWS.

The Sts package could be installed with Composer.

composer require async-aws/core

A new client object may be instantiated by:

use AsyncAws\Core\Sts\StsClient; $sts = new StsClient();

The authentication parameters is read from the environment by default. You can also specify a AWS access id and secret:

use AsyncAws\Core\Sts\StsClient; $sts = new StsClient([ 'accessKeyId' => 'my_access_key', 'accessKeySecret' => 'my_access_secret', 'region' => 'eu-central-1', ]);

For all available options, see the configuration reference.

Usage

Retrieve current Account

use AsyncAws\Core\Sts\StsClient; $sts = new StsClient(); $result = $sts->getCallerIdentity(); echo 'current Account:' . $result->getAccount();

Retrieve current Account

use AsyncAws\Core\Sts\Input\AssumeRoleRequest; use AsyncAws\Core\Sts\StsClient; $sts = new StsClient(); $result = $sts->assumeRole(new AssumeRoleRequest([ 'RoleArn' => 'arn:aws::iam::123456789012:role/demo', 'RoleSessionName' => 'demo-session', 'DurationSeconds' => 3600, ])); echo 'AccessKeyId:' . $result->getCredentials()->getAccessKeyId().PHP_EOL; echo 'SecretAccessKey:' . $result->getCredentials()->getSecretAccessKey().PHP_EOL; echo 'SessionToken:' . $result->getCredentials()->getSessionToken();

The source code to this page is found on GitHub.