β Day 8 of My Cloud Journey β β IAM Roles + EC2 to S3 Access Without Credentials π

Table of contents
On Day 8 of my #30DaysOfCloud journey, I went hands-on with IAM Roles and saw how an EC2 instance can access S3 without hardcoding any credentials.
This is a foundational AWS best practice β using IAM Roles for secure, temporary permissions.
π Problem Statement
We want an EC2 instance to:
Access an S3 bucket (read/write)
Without using access keys or credentials
Securely using IAM Roles
π What is an IAM Role?
An IAM Role is a set of permissions you can assign to AWS services.
Unlike IAM users, roles donβt have long-term credentials.
Instead, services like EC2 assume roles, and AWS automatically provides short-term access tokens to them.
π‘ This is safer, more scalable, and follows best practices!
π§ Step-by-Step: Allow EC2 to Access S3 Using IAM Role
1οΈβ£ Create an IAM Role
Go to IAM β Roles β Create Role
Select Trusted Entity:
AWS service
Choose EC2 as the use case
Attach the policy:
AmazonS3FullAccess
(or create a custom policy for least privilege)Name your role:
EC2S3AccessRole
β Done! Role created.
2οΈβ£ Launch (or modify) an EC2 instance
Launch a new EC2 instance (or stop β modify an existing one)
Under "IAM Role", attach
EC2S3AccessRole
Boot the instance and connect using SSH
3οΈβ£ Access S3 from EC2 (No Keys Needed!)
Log into your EC2 instance via SSH and test S3 access:
bashCopyEdit# List buckets
aws s3 ls
# Copy a file to S3
echo "Hello from EC2" > test.txt
aws s3 cp test.txt s3://your-bucket-name/
π« No access keys, no .aws/credentials
needed β it works using role-based access!
π§ͺ How It Works (Under the Hood)
EC2 instance has metadata service (
http://169.254.169.254
) which provides temporary credentialsAWS CLI automatically uses those credentials
These are rotated automatically and scoped to the permissions defined in the role
β Best Practices
π Use roles instead of access keys
π Roles rotate credentials automatically
π¦ Use least privilege β create scoped policies instead of S3FullAccess
π Use CloudTrail to monitor access
π― Summary
IAM Roles are a cornerstone of cloud security and automation.
Today, I learned:
How to assign IAM roles to EC2
How EC2 accesses S3 securely
That roles > access keys in almost every case!
π Resources
π Tomorrow: Iβll explore Amazon S3 in detail β buckets, object storage, lifecycle rules, and real-world use cases.
Letβs keep learning and building!
#30DaysOfCloud #AWS #IAM #EC2 #S3 #CloudSecurity #LearnInPublic #Hashnode #CloudJourney
Subscribe to my newsletter
Read articles from Pratik Das directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
