
aws iam create-user --user-name adminuser
2. By this time if you want to list the user, you should see it with the following command:
aws iam list-users
3. To create a user "adminuser":
aws iam create-user --user-name adminuser
4. You can also see if the new user created is in any group, which return a null value, as it doesn't belong to any group:
aws iam list-groups-for-user --user-name adminuser
IAM Profiles
5. We would also like to set up a password for the user 'adminuser'. There are many ways to do that. Here is one of the ways: Create a profile for the user together and using the profile template, we assign the password:
Generate a skeleton:
aws iam create-login-profile --generate-cli-skeleton > create-adminuser-profile.json
Then fill in the username and password details in the JSON file:
cat create-adminuser-profile.json { Â Â "UserName": "adminuser", Â Â "Password": "enter your passphrase here", Â Â "PasswordResetRequired": true }Create the profile
aws iam create-login-profile --cli-input-json file://create-adminuser-profile.json
It should look like this:
aws iam create-login-profile --cli-input-json file://create-adminuser-profile.json
{
  "LoginProfile": {
    "UserName": "adminuser",
    "CreateDate": "2022-03-18T11:43:43Z",
    "PasswordResetRequired": true
  }
}
6. Create an Access key. When creating the Access key, it means that you are allowed to sign in to AWS using AWS CLI or API (Programmatic access). If the Access key is not created, then that user will have access only to the AWS web portal. Save this key when using the command below.
aws iam create-access-key --user-name adminuser
IAM Groups
7. There are 2 ways to add policy. It's either on the user itself or to the group the user has been assigned. In practice, it is better to add the user to a group and that group should have its policy attached to it. So let's create a group:
aws iam create-group --group-name AdminGroup
8. After creating the group, you should be able to see it using the list-group command:
aws iam list-groups
9. To add the user to the group:
aws iam add-user-to-group --group-name AdminGroup --user-name adminuser
10. I can also list all groups a user belongs to:
aws iam create-group --group-name AdminGroup
11. In case you want to remove a user from a group:
aws iam remove-user-from-group --user-name adminuser --group-name AdminGroup
aws iam list-policies | grep PolicyName | wc -l
928
13. Let's now add the AdministratorPolicies to the group:
Here is the policy using list-policies
aws iam list-policies | grep "AdministratorAccess"
      "PolicyName": "AdministratorAccess",
      "Arn": "arn:aws:iam::aws:policy/AdministratorAccess",
Adding the policy to the group using attach-group-policy(AWS CLI use the verb "attach" when adding a policy to a group
aws iam attach-group-policy --group-name AdminGroup --policy-arn arn:aws:iam::aws:policy/AdministratorAccess
14. To check the policies attached to a group
aws iam list-attached-group-policies --group-name AdminGroups