A S3 bucket can be mounted in a AWS instance as a file system using S3fs. S3fs is a FUSE file-system that allows you to mount an Amazon S3 bucket as a local file-system. It behaves like a network attached drive, as it does not store anything on the Instance, but user can access the data on S3 from the instance.
Filesystem in Userspace (FUSE) is a simple interface for userspace programs to export a virtual file-system to the Linux kernel. It also aims to provide a secure method for non privileged users to create and mount their own file-system implementations.
Step-1:- Install Latest version of S3FS.
On Ubuntu :
sudo apt-get install automake autotools-dev fuse g++ git libcurl4-gnutls-dev libfuse-dev libssl-dev libxml2-dev make pkg-config
On CentOS :
sudo yum install automake fuse fuse-devel gcc-c++ git libcurl-devel libxml2-devel make openssl-devel
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 sudo make install
Step-2:- Use below command to check where s3fs command is placed in O.S. It will also tell you the installation is ok.
$ which s3fs
Step-3:- Getting the access key and secret key.
You will need AWS Access key and Secret key with appropriate permissions in order to access your s3 bucket from your EC2 instance. You can easily manage your user permissions from IAM (Identity and Access Management) Service provided by AWS.
Step-4 :- Create a new file in /etc with the name passwd-s3fs and Paste the access key and secret key in the below format .
echo AWSACCESSKEY:AWSSECRETKEY > /etc/passwd-s3fs chmod 640 /etc/passwd-s3fs
Step-5:- Now create a directory and mount S3bucket in it. Here, Provide your S3 bucket name in place of “mybucket”.
Run s3fs with an existing bucket
mybucket and directory
s3fs mybucket /path/to/mountpoint -o passwd_file=/etc/passwd-s3fs -o allow_other
where, mybucket is the name of your bucket, allow_other is to allow other users to write to the mount-point.
You can unmount it later by simply using the below command.
You can make an entry in /etc/rc.local to automatically remount after reboot. Find the s3fs binary file by “which” command and make the entry before the “exit 0” line as below.
You can also mount on boot by entering the following line to
s3fs#mybucket /path/to/mountpoint fuse _netdev,allow_other 0 0