Mounting S3 bucket into an EC2 instance

27 / Jan / 2014 by abhishek.tomar 1 comments

One of our clients has hosted his application on AWS and it uses EC2 instances behind the load balancer. The application provides an interface where users are suppose to upload files. For saving the same on centralize location we use S3 bucket and mount the same on the EC2 instances. Following are the step which we follow to get the things working:

Prerequisite : First we execute the following command, which will install the required packages necessary to install S3fs command.

Debian:

sudo apt-get install make gcc g++ pkg-config libfuse-dev libcurl4-openssl-dev libxml2-dev

Amazon AMI:

yum remove fuse fuse*fuse-devel
yum install gcc libstdc++-devel gcc-c++ curl-devel libxml2-devel openssl-devel mailcap fuse fuse-devel

Now we download the S3fs code, untar it and install it by using following command:

cd /opt
wget http://s3fs.googlecode.com/files/s3fs-1.71.tar.gz
tar xzvf s3fs-1.71.tar.gz
cd s3fs-1.71/
./configure
make
make install 
The above command will build and  install the S3fs.
In the next step we will create a file which stores the access key and secret key of our account (you can find the same under AWS Menu -> Your Account -> Security Credentials).
vim /etc/passwd-s3fs

Now we will store our secret key and access key like following:

chmod 640 /etc/passwd-s3fs
Now we will set the allow_other mount option so even if we are mounting the bucket using non root account, they can have permission to use allow_other option.
For this (to uncomment user_allow_other in fuse configuration file), we will execute the following command,
sed -ie 's/#user_allow_other/user_allow_other/g' /etc/fuse.conf
Now we will create a directory where we want to mount our S3 bucket,
mkdir /var/www/uploads
Now we can mount our bucket by running the below mentioned command:
s3fs <bucketname> -o use_cache -o allow_other /var/www/uploads
Now if above provided credentials are right and the bucket exists, it will mount the bucket on /var/www/uploads folder.
To check the same we can use the mount -l command and look for /var/www/uploads .
I hope this blog was helpful for you in Mounting S3 bucket to EC2 instance.
FOUND THIS USEFUL? SHARE IT

comments (1 “Mounting S3 bucket into an EC2 instance”)

  1. Sunil

    Connection established, waiting for welcome message…
    Response: 220 (vsFTPd 2.2.2)
    Command: USER backup
    Response: 530 Permission denied.
    Error: Could not connect to server

    Getting error after connecting to ftp. User default directory set as s3 bucket mounted folder.

    Reply

Leave a comment -