Everything needs permission to perform tasks in AWS. If you don't already understand IAM users and roles, you're missing an important part of AWS. In this article, you will learn, step-by-step, how to create an Identity and Access Management (IAM) user and an IAM role to control permissions.

IAM is an AWS service that allows you to interact with using for tasks like accessing the AWS Management Console, connecting with various tools and more. Sit back and learn how to get started with IAM and build a brand new IAM user and role.

Tutorial Overview

This article is structured like a tutorial. You will get a hands-on look at how to create an IAM role and an IAM user for authentication to AWS cloud services. There is a boundless amount of different IAM roles and users that can be created. Some are pre-defined and others you can fully customize.

In this tutorial you will:

  • Create an IAM user in the AWS console
  • Assign programmatic access to the user
  • Attach IAM existing policies to the user
  • Create an IAM Lambda role in the AWS console
  • Assign permissions to the IAM role
When creating a new IAM user in AWS, you can use two methods for access, console access and programmatic access. Console access gives users access to log into the AWS console by using the UI and programmatic access gives users access to work with the AWS SDK.

Enough talk, let's get started!

Creating an IAM User

Your first task will be to create an IAM user. An IAM user allows you to authenticate across many different AWS services. To create the IAM user, first navigate to IAM in the management console. You will see a welcome page with IAM Resources as shown in the screenshot below.

Click on Users on the left-hand side of the screen.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e7c5a7bd-1c63-49e2-8bc7-394a618be2e5/1.jpg

Once you are on the Add user page, click the Add User button. You will see a two options: User name which can be anything you'd like and Access type. Access type indicates how the IAM user will be used.

If you plan to connect to AWS via tool like the AWS CLI IAM, SDK or other, choose Programmatic access. If you're setting up a user to access the management console only, choose AWS Management Console access. For this demonstration, check the box next to Programmatic access.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e7249409-af77-43a5-9731-3479fc1f62c1/2.jpg

Click on Next: Permissions to get started assigning permissions.

Assigning IAM User Permissions

Once you've defined the username, it's time to start assigning permissions to this user. Permissions give the IAM user the ability to interact with various AWS services through policies.

Before assigning permissions, always track down what permissions the user will need. Do not assign overly lax permissions!

For this article, no specific permissions are necessary. Let's find a few existing policies to attach to this IAM user. Click on Attach existing policies directly and search for an example policy called AWSLambdaFullAccess. This policy is used for an AWS Lambda function.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e275f332-ab0d-4dbb-84fd-fc332ed4002f/5.jpg

Assigning Tags

Once the permissions are attached to the user, click the Next: Tags button. Tags are a great way to organization resources in AWS. For this tutorial though, they aren't necessary

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/74addc0c-4a1f-4183-8b82-9713e8306bcd/6.jpg

Completing IAM User Setup

At this point, the IAM user set up is complete. Click the Create user button as seen below to create the IAM user.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e204696a-0e3f-42af-a756-2f8e475137b8/7.jpg

Now that the user is created, you'll be presented with two critical pieces of information - the Access Key ID and the Secret access key. You will need to provide these two items to the AWS CLI and other tools to successfully authenticate to AWS.

The secret access key is only displayed once. Be sure to copy and store it in a safe place like a password manager.

Once you've copied the access key ID and the secret access key, it's time to create the IAM role.

Creating an IAM Role

In the last section, you created an IAM user and assigned permissions directly to it. But what if you have a more complex setup that needs that set of permissions available to multiple users? One way to do that is with IAM roles.

IAM roles are essentially "groups" of permissions that various users can attach to inherit those permissions. In this section, you're going to create a role for the AWS Lambda service.

To get started, navigate to IAM and instead of clicking on Users, click on Roles this time. Once the page comes up, click on the Create role button as you can see below.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/383170e4-4fb6-4d1e-bd3e-d4db1c132f0c/9.jpg

Assigning a Type of Role

The next step is to tell IAM what you're going to use this role for. For this tutorial, choose AWS service. Since the role to create will be used by Lambda, choose Lambda or whatever service you intend this role to access.

When you're done, click on the Next: Permissions button as shown below.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/3817aa29-9a79-4e71-8f2a-d6b92fc0be33/Untitled.png

Attaching IAM Role Permission Policies

The next step is to assign a policy or policies to the role. For this example, we'd like the role to have full control over all EC2 instances in the account. Filter the policies by typing AmazonEC2Full in the  Filter policies box and the policy should come up.

When the policy shows up, select the checkbox by the policy and click on Next: Tags to continue to the tags screen.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/25961c97-9cb5-4363-9e94-534f3f44a0b6/Untitled.png

Assigning Tags

Since we don't need to assign any tags to this role, click the Next: Review button.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/91b34595-a899-48d3-939b-256816ecb59d/Untitled.png

Completing IAM Role Setup

The final screen allows you to review all settings before actually creating the role. You will see five fields - Role name, Role description, Trusted entities, Policies and Permissions boundary.

  • Role description - this is generated by default but you can change it to your liking
  • Trusted entities - IAM users are associated with a specific person. IAM roles are different. An IAM role is instead a trusted entity which assumes a task to achieve. In this tutorial, that task is to create an EC2 instance.

Provide a Role name and click Create role as shown below.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/baa08522-e82b-4994-906a-d89348931313/12.jpg

You have now successfully created an IAM role!

Summary

In this blog post, you took a hands-on approach to create IAM users and roles. While working with IAM users and roles, you created permissions. You ensured while creating permissions that the IAM user and IAM role had permissions attached so they could access AWS resources. Once an IAM user and role is created, you can attach various policies. Using the AWS console you created the necessary IAM user, role, and attached the needed policies.

For your next challenge, create a custom IAM role that doesn't have a pre-made policy. This link should help get you started.