IAM
AWS
Cloud Security
User Management
Access Control

How to assign IAM role to users or groups

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

In the world of cloud computing and infrastructure management, managing permissions and access control is critical to ensuring security. AWS Identity and Access Management (IAM) is a service that helps you securely control access to AWS services and resources. One of the core features of IAM is the ability to attach policies to users and groups through IAM roles. This article provides a comprehensive guide on how to assign IAM roles to users or groups with detailed technical explanations and examples.

What are IAM Roles?

IAM roles are similar to IAM users in that they define a set of permissions for making AWS service requests. However, an IAM role does not have credentials associated with it (such as a password or access keys). Instead, IAM roles are intended to be assumed by entities such as users, groups, or services that need temporary permissions to carry out certain actions.

Advantages of Using IAM Roles

  1. Security: Provides temporary credentials, reducing the risk of credential theft.
  2. Flexibility: Roles can be assumed by different users or services, making them versatile.
  3. Granular Access Controls: Fine-tune permissions for specific actions.

Assigning IAM Roles to Users or Groups

Pre-requisites

  • An AWS account with administrative privileges to access IAM services.
  • Basic knowledge of IAM and AWS Management Console.

Steps to Assign IAM Role to Users or Groups

Step 1: Create an IAM Role

  1. Log in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/.
  2. In the navigation pane, select Roles and click on Create role.
  3. Select the AWS service that will use this role. For example, if you want the role to be assumed by EC2, choose EC2.
  4. Click Next: Permissions.
  5. Attach appropriate policies. For example, if the role needs S3 access, attach the AmazonS3FullAccess policy.
  6. Proceed with the Next: Tags (optional) step to add metadata tags.
  7. Review all your choices and click on Create role.

Step 2: Assign IAM Role to a User or Group

Assign to a User
  1. Navigate to the IAM console, select Users in the navigation pane.
  2. Click on the specific user to whom you want to assign the role.
  3. Under the Permissions tab, click Add permissions.
  4. Select Attach existing policies directly or Add inline policy.
  5. Attach the policy that allows the user to sts:AssumeRole for the specific role.
  6. Review and add permissions.
Assign to a Group
  1. Select Groups under the IAM console.
  2. Choose the necessary group where you want the role to be applicable.
  3. Repeat the same procedure as assigning a role to a user by adjusting permissions or policies attached to that group.

Example: Policy to Assume a Role

Here's an example JSON policy that grants a user permission to assume a specific IAM role:

  • Least Privilege Principle: Always ensure the least permissions possible are granted to perform necessary tasks.
  • Regular Audits: Periodically audit permissions and usage logs to maintain security posture.
  • Role Management: Keep roles organized and delete unused roles to minimize security risks.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.