How to Find and Delete Unused AWS IAM Roles
Learn how to identify and delete unused AWS IAM roles to enhance security and reduce risk. Explore how to remove them automatically with Blink.
Learn how to identify and delete unused AWS IAM roles to enhance security and reduce risk. Explore how to remove them automatically with Blink.
Finding and removing unused IAM roles that are not being actively monitored is a part of best security practices. You can remove the IAM role and its associated permissions as an administrator or developer.
In this guide, we’ll show you how to find unused IAM roles in AWS and remove them.
You can find unused IAM roles by either using the AWS Console or the AWS CLI. Let’s start with the Console.
1. Sign into the AWS IAM console and select Roles from the navigation panel.
2. You can view the Last activity column to sort by the number of days since the role was last used to make an AWS service . If the role has not been used within the tracking period of 400 days, the activity will display None.
3. You can learn more about the specific IAM role by clicking into its Summary page. On the Summary page, you will also be able to see Last activity, displaying the date when the role was last used to make an AWS service request.
4. Back out to the Roles list. When you are confident that you know which roles you want to remove, check the box next to the unused role you want to delete and hit the Delete button.
Here are the steps for finding and deleting unused IAM roles with the AWS CLI:
1. First, you can list all IAM roles using the following command:
You can narrow the targeting by including a page prefix parameter, like this:
Here’s an example output:
Now that you have a list of roles, you can see which ones are or are not being actively used.
2. Use the following command to check the RoleLastUsed, LastUsedDate, and the Region of a given role:
If RoleLastUsed does not contain a value, the role hasn’t been used within 400 days.
3. Get all instance profiles associated with the unused role and remove them.
First, you can run the following command to get a list of all instance profiles associated with the unused role:
Once you have the instance profiles, you can run the following command to remove all instance profiles from the unused IAM role:
4. Get all policies associated with the unused IAM role and delete them.
First, you can use the following command to list all inline policies in the role:
Next, you can run the following command to delete those policies from the role:
5. Use the following command to delete the unused IAM role:
Now, you have cleaned up an unused IAM role in your AWS account.
Running this check for unused IAM roles manually requires time and context-switching. You could try to automate it with a script, but if it breaks, it might need to be rewritten over time.
With Blink, you can easily create an automation that handles this check and sends unused IAM roles to you in a Slack message so you can approve their removal.
Get started with Blink today and strengthen your AWS security today.
Blink is secure, decentralized, and cloud-native. Get modern cloud and security operations today.