Create, manage permissions and delete IAM users using AWS CLI

Updated On February 12, 2021 | By Mahesh Mogal

In the last article, we have learned to manage IAM users with Python. Today we are going to perform the same operations using AWS CLI. Let's get started.

Creating IAM User in CLI

We can create an IAM user using "create-user" command. We can get information about AWS CLI commands using the help option. When you run "aws iam create-user help" command you will see the following output.

manage IAM users with AWS CLI - AWS CLI create user help

For creating a user we need to give user name which is required and other parameters are optional.

We can also add tags to a new user while creating him/her.

Attaching Policy to IAM user

When we create a new user he/she does not have any permission to access AWS resource. We have to add the required permissions to each user. We can do that by attaching IAM policies to each user. Let us attach S3 read-only policy to a user using AWS CLI.

We can validate that this user has S3 read-only policy in AWS console.

Adding user to a group using AWS CLI

Attaching individual user policies is not feasible when you have hundreds of users. It is considered the best practice to create IAM groups and then attach policies to the group. In this way, we can manage user permissions at the group level easily. We need to make sure that the group is already created before we add a user to that group. Let us see how we create an IAM group and then add a user to that group.

We can validate this on the console that the user has been added to the HR group.

Listing all users in AWS account in CLI

Listing to all users in IAM is very easy. We can use the following command.

If there are hundreds of users we can limit the number of users returned by this command using --max-items option.

Get user Details

We can get details about a specific user using 'get-user' command.

Delete user

There are often cases where we need to delete the IAM user. But before deleting user we need to remove it from all groups that the user is part of. We also need to remove individual policies attached to that user. Then only we can delete that user. Let us write CLI command to achieve the same.


In this article, we have managed IAM users using AWS CLI. We have written commands for creating, listing, adding policies and deleting users from IAM. These are not only operations that we can perform using AWS CLI. In the next articles, we will learn more about AWS and how we can manage its resources using CLI.


Mahesh Mogal

I am passionate about Cloud, Data Analytics, Machine Learning, and Artificial Intelligence. I like to learn and try out new things. I have started blogging about my experience while learning these exciting technologies.

Stay Updated with Latest Blogs

Get latest blogs delivered to your mail directly.

Recent Posts

Where and Filter in Spark Dataframes

In this blog, we will learn how to filter rows from spark dataframe using Where and Filter functions.

Where and Filter in Spark Dataframes
Read More
Distinct Rows and Distinct Count from Spark Dataframe

Getting distinct values from columns or rows is one of most used operations. We will learn how to get distinct values as well as count of distinct values.

Distinct Rows and Distinct Count from Spark Dataframe
Read More
Sorting in Spark Dataframe

In this blog, we will learn how to sort rows in spark dataframe based on some column values.

Sorting in Spark Dataframe
Read More

Leave a Reply

Your email address will not be published. Required fields are marked *

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
Share via
Copy link
Powered by Social Snap