In this tutorial, we will show you how to mount S3 bucket as a mount point to linux Instance
In my previous blog you will find ,,How to Mount S3 bucket with EC2 linux Instance using Access and Secret Key.
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.
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 policy and attached to an ec2 insance
Navigate to IAM policyand create s3-mounting-policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:DeleteObject",
"s3:ListObject",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::mounting0001/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::mounting0001"
]
}
]
}
save
Create a role S3-mounting-role and attached this policy
Navigate to EC2 console and attached this iam role S3-mounting-role
Action > Instance Setting > Attach/Replace IAM Role
Step 6- Now create a mount point
sudo mkdir /demobucket
Step 7- Add the below entry in fstab
sudo vi /etc/fstab
s3fs#mounting0001 /demobucket fuse _netdev,allow_other,uid=1002,gid=1002,iam_role=S3-mounting-role,use_cache=/tmp,url=https://s3.us-east-1.amazonaws.com 0 0
sudo mount -a
it will mount this bucket as a directory
Step 8- Check the mount point
df -h
Here you can see we have successfully mounted the S3 bucket on your EC2 Instance