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.
[shell]sudo apt-get install make gcc g++ pkg-config libfuse-dev libcurl4-openssl-dev libxml2-dev[/shell]
[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:
tar xzvf s3fs-1.71.tar.gz
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).
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,
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.