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

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

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

IAM 使用者是您在其中建立代表AWS使用該使用者或服務進行互動的實體AWS。AWS 中的使用者包含名稱和憑證。

下列範例示範如何:

所有的範例程式碼都可以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()); }