Create IAM users and groups - Amazon Command Line Interface
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

This documentation is for Version 1 of the Amazon CLI only. For documentation related to Version 2 of the Amazon CLI, see the Version 2 User Guide.

Create IAM users and groups

This topic describes how to use Amazon Command Line Interface (Amazon CLI) commands to create an Amazon Identity and Access Management (IAM) group and a new user, and then add the user to the group. For more information on the IAM service, see the Amazon Identity and Access Management User Guide.

Before you run any commands, set your default credentials. For more information, see Configure the Amazon CLI.

To create a group and add a new user to it
  1. Use the create-group command to create the group.

    $ aws iam create-group --group-name MyIamGroup { "Group": { "GroupName": "MyIamGroup", "CreateDate": "2018-12-14T03:03:52.834Z", "GroupId": "AGPAJNUJ2W4IJVEXAMPLE", "Arn": "arn:aws-cn:iam::123456789012:group/MyIamGroup", "Path": "/" } }
  2. Use the create-user command to create the user.

    $ aws iam create-user --user-name MyUser { "User": { "UserName": "MyUser", "Path": "/", "CreateDate": "2018-12-14T03:13:02.581Z", "UserId": "AIDAJY2PE5XUZ4EXAMPLE", "Arn": "arn:aws-cn:iam::123456789012:user/MyUser" } }
  3. Use the add-user-to-group command to add the user to the group.

    $ aws iam add-user-to-group --user-name MyUser --group-name MyIamGroup
  4. To verify that the MyIamGroup group contains the MyUser, use the get-group command.

    $ aws iam get-group --group-name MyIamGroup { "Group": { "GroupName": "MyIamGroup", "CreateDate": "2018-12-14T03:03:52Z", "GroupId": "AGPAJNUJ2W4IJVEXAMPLE", "Arn": "arn:aws-cn:iam::123456789012:group/MyIamGroup", "Path": "/" }, "Users": [ { "UserName": "MyUser", "Path": "/", "CreateDate": "2018-12-14T03:13:02Z", "UserId": "AIDAJY2PE5XUZ4EXAMPLE", "Arn": "arn:aws-cn:iam::123456789012:user/MyUser" } ], "IsTruncated": "false" }