Managing IAM users with Amazon SDK for PHP Version 3 - Amazon SDK for PHP
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Managing IAM users with Amazon SDK for PHP Version 3

An IAM user is an entity that you create in Amazon to represent the person or service that uses it to interact with Amazon. A user in Amazon consists of a name and credentials.

The following examples show how to:

All the example code for the Amazon SDK for PHP is available here on GitHub.

Credentials

Before running the example code, configure your Amazon credentials, as described in Credentials. Then import the Amazon SDK for PHP, as described in Basic usage.

Create an IAM user

Imports

require 'vendor/autoload.php'; use Aws\Exception\AwsException; use Aws\Iam\IamClient;

Sample Code

$client = new IamClient([ 'profile' => 'default', 'region' => 'us-west-2', 'version' => '2010-05-08' ]); try { $result = $client->createUser(array( // UserName is required 'UserName' => 'string', )); var_dump($result); } catch (AwsException $e) { // output error message if fails error_log($e->getMessage()); }

List IAM users

Imports

require 'vendor/autoload.php'; use Aws\Exception\AwsException; use Aws\Iam\IamClient;

Sample Code

$client = new IamClient([ 'profile' => 'default', 'region' => 'us-west-2', 'version' => '2010-05-08' ]); try { $result = $client->listUsers(); var_dump($result); } catch (AwsException $e) { // output error message if fails error_log($e->getMessage()); }

Update an IAM user

Imports

require 'vendor/autoload.php'; use Aws\Exception\AwsException; use Aws\Iam\IamClient;

Sample Code

$client = new IamClient([ 'profile' => 'default', 'region' => 'us-west-2', 'version' => '2010-05-08' ]); try { $result = $client->updateUser([ // UserName is required 'UserName' => 'string1', 'NewUserName' => 'string' ]); var_dump($result); } catch (AwsException $e) { // output error message if fails error_log($e->getMessage()); }

Get information about an IAM user

Imports

require 'vendor/autoload.php'; use Aws\Exception\AwsException; use Aws\Iam\IamClient;

Sample Code

$client = new IamClient([ 'profile' => 'default', 'region' => 'us-west-2', 'version' => '2010-05-08' ]); try { $result = $client->getUser([ 'UserName' => 'string', ]); var_dump($result); } catch (AwsException $e) { // output error message if fails error_log($e->getMessage()); }

Delete an IAM user

Imports

require 'vendor/autoload.php'; use Aws\Exception\AwsException; use Aws\Iam\IamClient;

Sample Code

$client = new IamClient([ 'profile' => 'default', 'region' => 'us-west-2', 'version' => '2010-05-08' ]); try { $result = $client->deleteUser([ // UserName is required 'UserName' => 'string' ]); var_dump($result); } catch (AwsException $e) { // output error message if fails error_log($e->getMessage()); }