AWS SDK for PHP バージョン 3 での IAM ユーザーの管理 - AWS SDK for PHP

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS SDK for PHP バージョン 3 での IAM ユーザーの管理

IAM ユーザーは AWS で作成するエンティティであり、AWS とやり取りするためにこれを使用する人またはサービスを表します。AWS のユーザーは名前と認証情報で構成されます。

以下の例では、次の方法を示しています。

  • を使用して新しい IAM ユーザーを作成しますCreateUser

  • を使用して IAM ユーザーを一覧表示しますListUsers

  • を使用して IAM ユーザーを更新しますUpdateUser

  • を使用して IAM ユーザーに関する情報を取得しますGetUser

  • を使用して IAM ユーザーを削除しますDeleteUser

のすべてのサンプルコードAWS SDK for PHPは、 にあります GitHub

認証情報

サンプルコードを実行する前に、AWS の認証情報を設定します (認証情報 を参照)。AWS SDK for PHP からのインポート (基本的な使用法 を参照)。

IAM ユーザーの作成

インポート

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

サンプルコード

$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()); }

IAM ユーザーのリストを取得する

インポート

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

サンプルコード

$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()); }

IAM ユーザーを更新する

インポート

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

サンプルコード

$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()); }

IAM ユーザーに関する情報を取得する

インポート

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

サンプルコード

$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()); }

IAM ユーザーを削除する

インポート

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

サンプルコード

$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()); }