In this blog, we will show you the Steps to accessing S3 bucket through EC2 instance using the IAM role.
- We have already created a few buckets under our subscription for this demo.
- Also, we have created an EC2 instance for this testing purpose.
CREATING IAM ROLE
- Go-to IAM Management.
- Click on Roles link.
- Click on create role button.
- Select on EC2 service and click on Next for permission Window.
- Search for S3 related permissions. We chose AmazonS3FullAccess for this demo.
- No tags are given for this role. Then click on the Next button to review the selected settings.
- Provide the name and description for your role and click on the Create Role button.
- A new role has been created successfully.
ASSIGNING THE IAM ROLE TO AN INSTANCE
- Select the EC2 Instance and click on Actions.
- Go to Instance settings and click on Attach/Replace IAM Role option.
- Select the IAM role from the drop-down list and click on Apply.
- The role has been attached successfully.
- Login into the EC2 instance and make sure that you have installed AWS CLI on that machine.
- You can download the MSI file from this URL: https://docs.aws.amazon.com/cli/latest/userguide/install-windows.html#install-msi-on-windows
- Open the command prompt and list the available S3 buckets using below command.
aws s3 ls
Thanks for reading this blog. We hope it was useful for you to learn about accessing the S3 bucket from an EC2 instance through IAM role.