[AWS] How to allow EC2 instance to access S3 bucket

Purpose
In this article, let me explain how to access your S3 bucket from EC2 instance. You need to assign a role to your EC2 instance for S3 access.
How to create new IAM role for  S3 bucket access
Access IAM console from AWS Management Console.
And, click Roles.

Click Create role button.

Select AWS service and check EC2. Then, click Next: Permissions.

Next, check AmazonS3FullAccess and click Next: Tags.

You can input tag if necessary. And click Next: Review button.

Input Role name as you like, and click Create role.

You can see that new role is created successfully !!

How to allow EC2 instance to access S3 bucket.

Firstly, access EC2 console by AWS management console.

Then, click EC2 instance.

Click Action > Security > Modify IAM role.

Then, select IAM role that you’ve created in the previous procedure.
And, click Save button.

After saving, please check the Security setting and new role is assigned to EC2 instance.

Upload file to S3 bucket from EC2 instance.

Let’s upload test file to S3 bucket from EC2 instance.
Firstly, awscli needs to be installed to your EC2 instance.
Execute curl command and download awscliv2.zip.

Then, unzip downloaded file.
If you cannot execute unzip command, please install it by yum -y install unzip command.

Then, install awscli by executing install command.

Finally, execute aws s3 cp command.
In this case, I uploaded test.txt file to S3 bucket.

OK. Let’s access S3 bucket console and check if test.txt exists.
If you can see uploaded file, it is succeeded !!

That’s all for this topic. If you think this article is beneficial for me, I would be glad if you click below icon for my motivation.
ブログランキング・にほんブログ村へ

コメント