Monday, November 05, 2012

S3FS: Mounting an S3 Bucket in Ubuntu

Recently I had an app on EC2 that needed to manage files in an S3 bucket. Normally I would use a gem to handle the uploading etc., but I figured I would give s3fs a crack.

Essentially s3fs allows you to mount an S3 bucket as an external file system, allowing you to manage files transparently as part of the OS.

It was relatively simple to get it working on an EC2 instance running Ubuntu 10.04.3 LTS


 - install the dependencies
 - install s3fs
 - create the password file
 - add the s3 bucket to fstab
 - mount and symlink to deployment dir

Installing Dependencies:
$ sudo apt-get install build-essential libfuse-dev fuse-utils libcurl4-openssl-dev libxml2-dev mime-support

Install Fuse 2.8.4:
$ wget -O fuse-2.8.4.tar.gz
$ tar xvzf fuse-2.8.4.tar.gz
$ cd fuse-2.8.4
$ ./configure --prefix=/usr
$ make
$ sudo make install

Install S3FS:
$ wget
$ tar xvzf s3fs-1.61.tar.gz
$ cd s3fs-1.61/
$ ./configure --prefix=/usr
$ make
$ sudo make install

Create /etc/passwd-s3fs:
$ sudo vim /etc/passwd-s3fs

Populate it with

Change permissions:
$ sudo chmod 640 /etc/passwd-s3fs

Add Mount Point:
$ sudo mkdir /mnt/bucket

Add to FSTAB:
s3fs#[bucket-name] /mnt/bucket fuse netdev,default_acl=public-read,use_cache=/tmp,use_rrs=1,allow_other 0 0

Symlink to Mount Point:
$ ln -s /mnt/bucket /[deployed_app_path]/public

$ AWSACCESSKEYID=[your_aws_access_id] AWSSECRETACCESSKEY=[your_aws_secret] sudo /usr/bin/s3fs [bucket-name] /mnt/bucket -odefault_acl=public-read


Josef van Niekerk said...

Thanks for this informative post, I'm using S3FS on multiple sites, and it really works a charm!

Daniel said...

It works great, thanks! Only when editing the fstab is better to omit the netdev because generate an error on mounting.