AWS: Mount S3 to Ec2 instances

Step1: Install S3FS

a) Install using yum (Centos /Redhat):

# sudo yum install s3fs-fuse

b) Install using apt-get ( Ubuntu):

# sudo apt-get install s3fs

c) Install from source code:

 # sudo yum install automake fuse fuse-devel gcc-c++ libcurl-devel libxml2-devel make openssl-devel
# cd /tmp
# wget https://github.com/s3fs-fuse/s3fs-fuse/archive/master.zip
# unzip master.zip
# cd  s3fs-fuse-master
# ./autogen.sh 
# ./configure --prefix=/usr 
# make
# sudo make install

Step2: Create S3 bucket or S3 Folder

You can create S3 bucket in AWS S3, if you want to mount folder you can create folder in existing bucket. for this tutorial, lets say bucket is s3bucket and folder is s3folder.

Step3: mount S3

Create a folder to mount

# mkdir -p /var/s3


We will be adding following entry into /etc/fstab based on our requirement.

a) Mounting as IAM role:

You can change iam_role value from auto to any specific role as required otherwise auto will auto detect role.

s3fs#s3bucket /var/s3 fuse _netdev,nonempty,mp_umask=022,allow_other,use_cache=/tmp,iam_role=auto,rw 0 0
b) Mounting S3 folder:
s3fs#s3bucket:/s3folder /var/s3 fuse _netdev,nonempty,mp_umask=022,allow_other,use_cache=/tmp,iam_role=auto,rw 0 0


In above example s3bucket is post-pended with folder name s3folder

c) mount with access key:

Create access file:

# echo ACCESS_KEY:SECRET_KEY > ~/.passwd-s3fs
# cat ~/ .passwd-s3fs ACCESS_KEY:SECRET_KEY
# chmod 600 .passwd-s3fs

Edit /etc/fstab:

s3fs#s3bucket /var/s3 fuse _netdev,nonempty,mp_umask=022,allow_other,use_cache=/tmp,rw 0 0

If you want to mount folder then edit /etc/fstab with following entry:

s3fs#s3bucket:/s3folder /var/s3 fuse _netdev,nonempty,mp_umask=022,allow_other,use_cache=/tmp,rw 0 0

Step 4: Final steps

Activate the mount:

# mount -a 

Check your mount:

# df

You should able to see all your mounts along with s3 mount.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s