How to Mount S3 bucket with EC2 linux Instance using Access and Secret Key.

In this tutorial, we will show you how to mount S3 bucket to linux Instance as a file system S3FS.

S3FS is a FUSE filesystem application backed by amazon web services simple storage service. S3FS can operate in a command mode or a mount mode. In mount mode, S3FS will mount an amazon S3 bucket (that has been properly formatted) as a local file system.

There was one requirement where the client wants to access files from s3bucket on Linux AWS EC2 box, where they can easily manage all files stored in S3 bucket via SFTP protocol.

Why S3 bucket Instead of EFS sort of solutions?

We have EFS from Amazon but it’s costly and even the same data were used for their analytics solution. So we thought to use S3 to satisfy both the requirement.

Following are the steps below to mount your S3 bucket to your linux Instance.

Step 1- Update Your System

Sudo yum update 

Step 2- Install the s3fs on linux

sudo yum install automake fuse fuse-devel gcc-c++ git libcurl-devel libxml2-devel make openssl-devel

Step 3- Download s3fs code from github

git clone https://github.com/s3fs-fuse/s3fs-fuse.git

Step 4- Compile and install the code

cd s3fs-fuse
./autogen.sh
./configure --prefix=/usr --with-openssl
make
sudo make install

Step 5- check if the s3fs is installed in your system or not

which s3fs

Step 6- Create an IAM user attach S3 permission to the user

you need access-key and secret key for s3buket user , store key details in /etc/passwd-s3fs

Step 7- Create a file passwd-s3fs and save access and secret key of the user

sudo vi /etc/passwd-s3fs

Step 8- Add access and secret key and provide specific permission to this file

Replace access-key-id and secret-access-key with your keys

save and exit

sudo chmod 640 /etc/passwd-s3fs

Step 9- Create a directory to mount

sudo mkdir /demobucket

Step 10- Mount the bucket

s3fs cloudsbaba /demobucket -o use_cache=/tmp -o allow_other -o uid=1001 -o mp_umask=002 -o multireq_max=5 -o use_path_request_style -o url=https://s3.console.aws.amazon.com/s3/home?region=ap-south-1

now check

df -h

when we reboot this instance it will unmount the bucket.

For this we make an entry in /etc/fstab

mybucket /path/to/mountpoint fuse.s3fs _netdev,allow_other 0 0

cloudsbaba /demobucket fuse.s3fs _netdev,allow_other 0 0

Step 11- Now create a file in /demobucket and check in S3 management console

Check the file in S3 console

Congrats.. you successfully follow all the steps and mount S3 bucket on a linux system

For more update and content please follow www.cloudsbaba.com

Recent Posts