Open In App

Mount AWS S3 Bucket On Amazon EC2-Instance

Last Updated : 25 Oct, 2023
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

AWS S3 storage service is used for object storage these objects can be termed a file and it's metadata that briefs about it. Well, to store the files and documents we need to create a S3 bucket. It's like a container that stores the files. These files can be pictures, txt file, documents, static web page files, etc. AWS S3 object storage is mostly used to store backup or archived files.

Why to Mount an AWS S3 Bucket on an AWS EC2 Instance?

  • Easy Access: Mounting an S3 bucket on your EC2 instance can make it easier to access and manage your data because you can use the required file and interact with objects in the bucket.
  • Easy to store backups Mounting S3 to your EC2 instance makes it easy to back up or restore files directly from your instance.
  • Cost-effective: It is cost effective to mount and use S3 that using it over the internet.
  • Security: By mounting it, we can attach IAM role and policy to the instance and restrict access to s3 bucket according to the need.

How to mount an S3 bucket on an EC2 Instance?

We are going to use Mountpoint for Amazon S3. This is an open source file client that makes it easy to directly connect to Amazon S3.

Step by Step guide to Mount AWS S3 Bucket on Amazon EC2-Instance

Step 1: Log in to your Console and search S3 --> Click on create bucket

Amazon s3

Step 2: Give it a unique name(follow S3 naming convention) -->Choose region(Keep other things as it is)--> Click on create

Create S3 bucket

Step 3: Now open the bucket--> Click on Upload --> Choose on Add file--> select file from system -->Click on Upload.

Uploading files to S3

Uploading files to s3

Step 4: Now let's create an instance, for that

Click on "launch instance"--> Give it a name--> Choose AMI(Here I have taken Linux 2 kernel)-->Choose t3.micro as instance type-->Go to advanced, In IAM instance profile--> Click on "Create new IAM profile"


Launch an Instance

Step 5:Click on Create role-->Click on AWS service--> in use case select EC2--> Now in permission search and select "S3fullaccess"-->Click Next-->give it a Name and Create

Creating IAM Role

Select trusted entity

Add permisssions

Step 6: Now in launch template--> In IAM instance profile--> refresh and select newly created IAM role.

Step 7: Now, after launching

SSH into the server.

SSH into server

Step 8: Run following coomands

# sudo su

# wget https://s3.amazonaws.com/mountpoint-s3-release/latest/x86_64/mount-s3.rpm

Retreive files using wget

Install the mount-s3

# yum install ./mount-s3.rpm

Install mount-s3

Now, use this command to list of all the buckets present in your AWS S3

# aws s3 ls

list all buckets in s3

Now create directory

# mkdir {name of directory}

Create Directory

Now to mount the required bucket

# mount-s3 s3bucketsaws[name of the bucket] mountedfolder/[directory where to be mounted]

Now, go to the directory and do "ls"

you can find your files.

Listing all files in bucket

That's all on how and why to mount S3 bucket.


Similar Reads