How to Create, Attach, and Detach IAM Roles in AWS

Photo by Toa Heftiba on UnsplashImagine that you have to manage and distribute security credentials to all the instances your application runs on, including those created by you and those AWS creates on your behalf using Auto Scaling groups. I bet it’l…


This content originally appeared on Level Up Coding - Medium and was authored by Chinedu Ikechi

Photo by Toa Heftiba on Unsplash

Imagine that you have to manage and distribute security credentials to all the instances your application runs on, including those created by you and those AWS creates on your behalf using Auto Scaling groups. I bet it’ll be challenging AF.

IAM roles was designed to enable your applications make secure API requests from your instances without having to manage the security credentials that the application uses.

An IAM role is similar to an IAM user, but instead of being uniquely associated with a one person, it can be assumed by anyone who needs it.

IAM roles are invaluable in AWS, and in this article, we’ll be looking at how to create, attach, and detach AWS IAM roles.

Creating IAM Roles for an AWS Service

There are various ways to create IAM roles in AWS. You can use the AWS Management Console, the AWS CLI, the Tool for Windows PowerShell, or the IAM api. In this tutorial, I’ll only cover how to create IAM roles via the AWS Management Console.

Steps:

  1. Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/
  2. In the navigation pane of the IAM console, choose Roles -> Create role

3. Under Trusted entity type section, select AWS service.

4. Under Use case, you’re to select the use case for your service, and here I’ll be going for EC2. When you’ve selected your use case, click Next.

5. Select one or more permission policies to attach to your new role. There are more than 750 roles you can choose from. You can also create a new policy by clicking on the Create Policy button on the top right corner. For this tutorial, I selected IAMReadOnlyAccess. This policy provides read-only access to IAM via the AWS management console. After choosing a permission policy, click next.

6. This is the last step. Here you’re to provide a Role name, optionally add tags to your role, and review the details of the role you’re about to create.

Role name helps you identify the purpose of the role you’re creating, and it must be unique within your AWS account.

Create Role name

IAM tags are key-value pairs that you can add to your role. Tags can include user information, such as email address.

Add Role tags

After providing a role name and reviewing the role, and if you’re satisfied with the details you’ve provided, click on create role to create the new role, else you can use the previous button to go back and edit. You can also click on cancel if you’d like to start all over again.

How to Attach an IAM Role to an Instance

We’re done creating our brand new IAM role, but how the we attach them to an instance?

Steps:

  1. In the navigation pane of the EC2 console, choose Instances.
Select Instances

2. Select an instance, and in the upper-right section, choose Action → Security → Modify IAM role.

Modify IAM role

3. Under the Modify IAM role section, click on the Choose IAM role dropdown and select the role you’ve created, after which you can click on the Update IAM role button to attach the role to your instance.

Select IAM role to attach to your instance.

How to Detach an IAM Role

If we no longer want an IAM role to be associated with an instance, we can easily detach it from the instance.

Steps:

  1. Chances are you’re already in the Instances Service, but if not, navigate to the Instances Service.
Navigate to Instances

2. Select an instance, and in the upper-right section, choose Action → Security → Modify IAM role.

Modify IAM role

3. Click on the Choose IAM role dropdown, select No IAM role and click on Update IAM role.

Select No IAM Role

4. In the confirmation dialog box, enter Detach and click on the Detach button.

Detach IAM role

In this guide, we looked at what IAM roles are, and how they enable our applications to make secure API requests from instances without having to worry about the security credentials that the application uses.

We also had a step-by-step look at how to create, attach, and detach IAM roles from an instance.

I hope this is easy to understand and implement, and you can always comment/reach out for questions and suggestions. ❤️

Level Up Coding

Thanks for being a part of our community! Before you go:

🚀👉 Join the Level Up talent collective and find an amazing job


How to Create, Attach, and Detach IAM Roles in AWS was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Chinedu Ikechi


Print Share Comment Cite Upload Translate Updates
APA

Chinedu Ikechi | Sciencx (2023-01-12T14:25:57+00:00) How to Create, Attach, and Detach IAM Roles in AWS. Retrieved from https://www.scien.cx/2023/01/12/how-to-create-attach-and-detach-iam-roles-in-aws/

MLA
" » How to Create, Attach, and Detach IAM Roles in AWS." Chinedu Ikechi | Sciencx - Thursday January 12, 2023, https://www.scien.cx/2023/01/12/how-to-create-attach-and-detach-iam-roles-in-aws/
HARVARD
Chinedu Ikechi | Sciencx Thursday January 12, 2023 » How to Create, Attach, and Detach IAM Roles in AWS., viewed ,<https://www.scien.cx/2023/01/12/how-to-create-attach-and-detach-iam-roles-in-aws/>
VANCOUVER
Chinedu Ikechi | Sciencx - » How to Create, Attach, and Detach IAM Roles in AWS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/01/12/how-to-create-attach-and-detach-iam-roles-in-aws/
CHICAGO
" » How to Create, Attach, and Detach IAM Roles in AWS." Chinedu Ikechi | Sciencx - Accessed . https://www.scien.cx/2023/01/12/how-to-create-attach-and-detach-iam-roles-in-aws/
IEEE
" » How to Create, Attach, and Detach IAM Roles in AWS." Chinedu Ikechi | Sciencx [Online]. Available: https://www.scien.cx/2023/01/12/how-to-create-attach-and-detach-iam-roles-in-aws/. [Accessed: ]
rf:citation
» How to Create, Attach, and Detach IAM Roles in AWS | Chinedu Ikechi | Sciencx | https://www.scien.cx/2023/01/12/how-to-create-attach-and-detach-iam-roles-in-aws/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.