Mounting S3 bucket into an EC2 instance

27 / Jan / 2014 by abhishek.tomar 2 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:

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

Amazon AMI:

[shell]yum remove fuse fuse*fuse-devel
yum install gcc libstdc++-devel gcc-c++ curl-devel libxml2-devel openssl-devel mailcap fuse fuse-devel[/shell]

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

[shell]cd /opt
wget
tar xzvf s3fs-1.71.tar.gz
cd s3fs-1.71/
./configure
make
make install [/shell]

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).
[shell]vim /etc/passwd-s3fs[/shell]

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

[shell]chmod 640 /etc/passwd-s3fs[/shell]

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,
[shell]sed -ie ‘s/#user_allow_other/user_allow_other/g’ /etc/fuse.conf[/shell]

Now we will create a directory where we want to mount our S3 bucket,

[shell]mkdir /var/www/uploads[/shell]

Now we can mount our bucket by running the below mentioned command:
[shell]s3fs <bucketname> -o use_cache -o allow_other /var/www/uploads[/shell]

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 (2)

  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 Reply

Your email address will not be published. Required fields are marked *