AWS IAM role is not listed in the IAM roles dropdown menu for EC2

By Saad Khamis

June 25, 2024

18289 views

In this blog, we will delve into a comprehensive solution to address this issue, ensuring that your IAM roles are correctly listed and available for assignment to EC2 instances. By following this step-by-step guide, you can resolve this issue efficiently and maintain a smooth and secure operational environment for your AWS resources.

Explore my other articles about AWS services:

Introduction

When managing AWS EC2 instances, encountering an issue where an IAM role is not listed in the IAM roles available for EC2 can be a frustrating roadblock. This problem can hinder your ability to manage permissions and access for your instances, potentially affecting the overall security and functionality of your applications. In this article, we will delve into a comprehensive solution to address this issue, ensuring that your IAM roles are correctly listed and available for assignment to EC2 instances. By following our step-by-step guide, you can resolve this issue efficiently and maintain a smooth and secure operational environment for your AWS resources.

Assumptions

  1. The AWS IAM role has already been created.
  2. The AWS EC2 instance is not associated with an IAM instance profile.

Prerequisites

  1. Install and configure AWS Tools for PowerShell.
  2. Log in to all required AWS accounts/profiles.
  3. Set your IAM permissions to allow access to the required resources.
  4. AWS EC2 InstanceId.

PowerShell Cmdlets

  1. New-IAMInstanceProfile Creates a new instance profile.
  2. Add-IAMRoleToInstanceProfile Adds the specified IAM role to the specified instance profile. An instance profile can contain only one role, and this quota cannot be increased.
  3. Register-EC2IamInstanceProfile Associates an IAM instance profile with a running or stopped instance. You cannot associate more than one IAM instance profile with an instance.
  4. Get-EC2IamInstanceProfileAssociation Describes your IAM instance profile associations.

Resolution

The dropdown list of IAM roles shows instance profiles instead of IAM roles. Therefore, if a specific IAM role is missing from the list, it might be because the corresponding instance profile is not present.

To resolve this issue, we will follow these three steps:

  1. Create a new instance profile.
  2. Add the required IAM role to the new instance profile.
  3. Associate the new IAM instance profile with a running or stopped EC2 instance.

First, create a new instance profile

We will ensure that the instance profile and IAM role have the same name.

Second, add the required IAM role to the new instance profile

Add the specified IAM role to the specified instance profile. An instance profile can contain only one role.

Third, associate the new IAM instance profile with an EC2 instance

Associate the new IAM instance profile with an EC2 instance. We cannot associate more than one IAM instance profile with an instance.

Finally, verify that the EC2 instance is associated with the IAM role

At last, we verify EC2 instance association.

All Script Commands

Without delay, we used the commands below to resolve the issue.

Additional information

Conclusion

I used PowerShell and AWS Tools for PowerShell to resolve the issue of an AWS IAM role is not listed in the IAM roles dropdown menu for EC2.

Did you find this blog easy to follow and helpful? I would love to hear your feedback and suggestions, so please share them in the comments below.

Disclaimer

Purpose of the code contained in blog is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.

Comments

There's no comments

Leave a Reply

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

Related Posts

List all AWS Certificate Manager certificates

By Saad Khamis 14098 views July 31, 2024

Get all AWS EBS snapshots across all profiles and regions

By Saad Khamis 18456 views June 26, 2024

Get all AWS EC2 instances across all profiles and regions

By Saad Khamis 33198 views November 27, 2023