Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅
中国的 Amazon Web Services 服务入门
(PDF)。
将 AddUserToGroup
与 Amazon SDK 或 CLI 配合使用
以下代码示例演示如何使用 AddUserToGroup
。
操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:
- .NET
-
- Amazon SDK for .NET
-
/// <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;
}
- CLI
-
- Amazon CLI
-
要将用户添加到 IAM 组
以下 add-user-to-group
命令可将名为 Bob
的 IAM 用户添加到名为 Admins
的 IAM 组。
aws iam add-user-to-group \
--user-name Bob \
--group-name Admins
此命令不生成任何输出。
有关更多信息,请参阅《Amazon IAM 用户指南》中的在 IAM 用户组中添加和删除用户。
- PowerShell
-
- 适用于 PowerShell 的工具
-
示例 1:此命令将名为 Bob
的用户添加到名为 Admins
的组中。
Add-IAMUserToGroup -UserName "Bob" -GroupName "Admins"
有关 Amazon SDK 开发人员指南和代码示例的完整列表,请参阅 将 IAM 与 Amazon 开发工具包配合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。