AWS - IAM
Introduction to AWS Identity and Access Management
Demo Creating IAM Role
In this step-by-step guide, you'll learn how to create an AWS Identity and Access Management (IAM) role that grants an Amazon EC2 instance permission to read objects from an S3 bucket named company1-logs
. By leveraging IAM roles, you avoid hardcoding credentials on your server and follow AWS best practices for secure access management.
Prerequisites
- An AWS account with administrative privileges
- A running EC2 instance
- An existing S3 bucket named
company1-logs
Step 1: Create the IAM Role
Open the IAM console, select Roles, then click Create role.
On Select trusted entity, choose AWS service.
Under Use cases for other AWS services, select EC2.
Click Next to move to the permissions page.
In Permissions, search for company1 and select the Company1 logs policy which grants
s3:GetObject
access to thecompany1-logs
bucket.Click Next, then enter a Role name (e.g.,
Company1-Logs-Role
) and an optional description.Review the Trust relationship to ensure EC2 can assume this role. It should resemble:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["sts:AssumeRole"], "Principal": {"Service": ["ec2.amazonaws.com"]} } ] }
(Optional) Add tags to categorize your role, then click Create role.
Note
You’ve successfully created an IAM role that EC2 instances can assume to access S3 resources securely.
Step 2: Attach the IAM Role to Your EC2 Instance
- Go to the EC2 console, select Instances, and choose your running instance.
- From the Actions menu, select Security > Modify IAM role.
- In the IAM role dropdown, pick Company1-Logs-Role.
- Click Update IAM role to apply the change.
Warning
If your EC2 instance already has an IAM role attached, updating it will replace the existing role and associated permissions. Ensure this change aligns with your security policies.
Your EC2 instance now inherits the permissions defined in Company1-Logs-Role
, allowing it to securely read log files from the company1-logs
bucket without embedded credentials.
References
Watch Video
Watch video content