Manage IAM Groups using Python and AWS CLI

Updated On February 12, 2021 | By Mahesh Mogal

In this article, we are going to manage AWS IAM Groups using Python and AWS CLI. IAM Groups are the recommended way to manage AWS permissions for a collection of users. Let us learn how we can master IAM group operations.

Create IAM Group

We can create the IAM group in the following ways in python and AWS CLI.

List All Groups in IAM

We can list all IAM groups in AWS.

We can achieve the same using AWS CLI using the following command

Adding Users to IAM Group

We can add users to the group with Python using the following script.

Using AWS CLI, we can run the following command to add a user to the group.

Listing All users in specific IAM group

Often, we might need to list all users who belong to a particular group. Using Python, we can list users using the following script.

For doing the same in AWS CLI, we need to run the following command.

Removing Users from IAM groups

We can remove users from the IAM group using python using the function below.

Attaching Policies to IAM Group

We can manage permissions for all users in the group with IAM policies. We can attache policy to IAM group and it will affect all users in that group. Let us write a script to attach a policy to the IAM group using Python.

Listing Attached policies to IAM Group

It is easier to manage policies for users at the group level. Any policy attached to that group will be applied to all of its members. We can check all policies attached to that group using the below method

We can do the same thing using AWS CLI as well.

Removing attached policies to IAM group

We can remove the attached policies to IAM groups.

Using AWS CLI, we can run below command

Deleting IAM group

In the last group operation of this article, we are going to learn how to delete the IAM group. Before deleting any group, we need to remove all members from that group and detach all policies attached to that group. Then only we will be able to delete the IAM group.


In this tutorial on AWS IAM, we have gone through how to manage IAM group operations like create, add user, add/remove policy and delete using python and AWS CLI. I hope you have found it useful. See you in the next article, until then keep learning 🙂

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

Spark Join Types With Examples

In this blog, we are going to learn different spark join types. We will also write code and validate data output for each join type to better understand them.

Read More
Integrate Spark with Jupyter Notebook and Visual Studio Code

In this blog, we are going to integrate spark with jupyter notebook and visual studio code to create easy-to-use development environment.

Read More
Reading Data From SQL Tables in Spark

In this blog, we are going to learn about reading data from SQL tables in Spark. We will create Spark data frames from tables and query results as well.

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