How to mount S3 Bucket on Ubuntu using S3FS

Today I will show you how I config to mount S3 Bucket as a local file system on Ubuntu 16.04.

What is an Amazon S3 bucket?

As a document, [Amazon S3 bucket] is storage for the Internet. It is designed to make web-scale computing easier for developers.

Create an Amazon S3 Bucket

First of all, you need register an AWS account to manage your buckets. Since you have the account, Amazon S3 provides APIs for you to create and manage buckets. By default, you can create 100 buckets limit. If you need additional buckets, you can increase your bucket limit by submitting a service limit increase. In each bucket, you can store any number of objects. See [create a bucket document]. Since you have a bucket, you can start mounting process.

Installation S3FS package

S3FS allows Linux and Mac OS X to mount an S3 bucket via FUSE.
Following S3FS guideline, we need to ensure all dependencies installed.

sudo apt-get install automake autotools-dev fuse g++ git libcurl4-gnutls-dev libfuse-dev libssl-dev libxml2-dev make pkg-config

Ensure libfuse2 and libfuse-dev packages are installed. Then compile from master via the following commands:

git clone https://github.com/s3fs-fuse/s3fs-fuse.git
cd s3fs-fuse
./autogen.sh
./configure
make && make install

Verify Fuse and F3FS installed
– Fuse

root@dac22c9e3125:/# pkg-config --modversion fuse
2.9.4

– F3FS

root@dac22c9e3125:/# s3fs --version
Amazon Simple Storage Service File System V1.82(commit:ab89b4c) with OpenSSL
Copyright (C) 2010 Randy Rizun <rrizun@gmail.com>
License GPL2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Then, enter your S3 identity and credential in a file /path/to/passwd and set owner-only permissions:

echo AccessKey:SecretKey > /path/to/passwd
chmod 600 /path/to/passwd

Mount an S3 bucket

Create a mount point directory for the S3 bucket and use the s3fs command to mount it.

1. Create a directory for mounting the S3 bucket

root@dac22c9e3125:/# mkdir /var/www/html/s3-bucket
root@dac22c9e3125:/# chmod -R 755 /var/www/html/s3-bucket

2. Create cache directory

root@dac22c9e3125:/# mkdir /tmp/cache 
root@dac22c9e3125:/# chmod -R 755 /tmp/cache

3. Mount the S3 bucket using the correct permissions and any other options

root@dac22c9e3125:/# s3fs -o allow_other -o use_cache=/tmp/cache mybucket /var/www/html/s3-bucket -o passwd_file=/.passwd-s3fs -o nonemprt

4. Verify the s3fs mounted file system

root@dac22c9e3125:/# df
s3fs on /var/www/html/s3-images type fuse.s3fs (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other)

5. You can also mount on boot

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