搭AddUserToGroup配 AWS SDK或使用 CLI - AWS Identity and Access Management

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

AddUserToGroup配 AWS SDK或使用 CLI

下列程式碼範例會示範如何使用AddUserToGroup

動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:

.NET
AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫

/// <summary> /// Add an existing IAM user to an existing IAM group. /// </summary> /// <param name="userName">The username of the user to add.</param> /// <param name="groupName">The name of the group to add the user to.</param> /// <returns>A Boolean value indicating the success of the action.</returns> public async Task<bool> AddUserToGroupAsync(string userName, string groupName) { var response = await _IAMService.AddUserToGroupAsync(new AddUserToGroupRequest { GroupName = groupName, UserName = userName, }); return response.HttpStatusCode == HttpStatusCode.OK; }
  • 如需詳API細資訊,請參閱AWS SDK for .NET API參考AddUserToGroup中的。

CLI
AWS CLI

若要將使用者新增至IAM群組

下列add-user-to-group指令會將名為的IAM使用者新增Bob至名為的IAM群組Admins

aws iam add-user-to-group \ --user-name Bob \ --group-name Admins

此命令不會產生輸出。

如需詳細資訊,請參閱《使用指南》中的〈在IAM使用者群組中新增和移除AWSIAM使用者〉

  • 如需詳API細資訊,請參閱AWS CLI 指令參考AddUserToGroup中的。

PowerShell
適用的工具 PowerShell

範例 1:此指令會將名為的使用者新增Bob至名為的群組Admins

Add-IAMUserToGroup -UserName "Bob" -GroupName "Admins"
  • 如需詳API細資訊,請參閱AWS Tools for PowerShell 指令程AddUserToGroup式參考中的。

如需 AWS SDK開發人員指南和程式碼範例的完整清單,請參閱使用此服務 AWS SDK。本主題也包含有關入門的資訊以及舊SDK版的詳細資訊。