使用第 3 AWS SDK for PHP 版管理 IAM 使用者 - AWS SDK for PHP

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用第 3 AWS SDK for PHP 版管理 IAM 使用者

IAM 使用者是您在 中建立的實體 AWS ,代表用來與之互動的人員或服務 AWS。中的使用者 AWS 包含名稱和登入資料。

下列範例示範如何:

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