Google+ Badge

Tuesday, March 15, 2016

How to mount AWS S3 bucket in linux EC2 instance using S3FS


If you have not created a S3 bucket kindly go through with EC2 documentation.The documentation is very clear and easy to understand .

S3FS is FUSE (File System in User Space) based solution to mount an Amazon S3 buckets. On s3fs mounted files systems we can simply use cp, mv and ls the basic Unix commands similar to run on locally attached disks. 

Step 1 - First, we want to update repository.

Step 2 - Before installing s3fs, we want to install dependencies.

Note : In this section may be we get dependency error like fuse-utils. In this case I have to go below example.

Step 3 - Download and Compile Latest Fuse package first using below command.
URL : wget http://downloads.sourceforge.net/project/fuse/fuse-2.X/2.9.3/fuse-2.9.3.tar.gz
    root@ip-172-31-24-7:~# ./configure
   root@ip-172-31-24-7:~# make
   root@ip-172-31-24-7:~# make install

Step 4 - Now we can install s3fs dependency packages on this server
apt-get install build-essential gcc libfuse-dev fuse-utils libcurl4-openssl-dev libxml2-dev mime-support build-essential libcurl4-openssl-dev

Step 5 - Download and Compile Latest S3FS using below example and extract.
URL : wget https://s3fs.googlecode.com/files/s3fs-1.61.tar.gz

Step 6 - Open /etc/fuse.conf file to make small change. Uncomment the line #user_allow_other.

Step 7 - Now getting the access key and secret key for adding /etc/passwd-s3fs file.

Click on AWS Menu => Your AWS Account Name => Security Credentials.
Here you can see access key and secret key (secret key is visible when you click on show tab). Copy these both keys separately and add on /etc/passwd-s3fs file.

Step 8 - Create a new file under the /etc/ with the name passwd-s3fs and Paste the access key and secret key in this manner => "accesskey:secretkey". And also change the permission.

Step 9 - Now create a directory to mount S3bucket in /mnt directory and mount S3 bucket using below example.
Note: you can get bucket name from S3 management console.

Step 10 -  To check mounted S3 bucket using below command.

Step 11 - We can create file and folder for testing purpose.

Step 12 - Go to AWS S3 bucket control Panel and check the file is there.

Step 13 - Unmount we created S3 bucket and check it.

Note : Here, we unmount the S3 Bucket from the EC2 server. But we can see the file in S3 control panel.

Step 14 - File uploading through AWS S3 bucket directly.

Step 15 - Again we can re-mount and check the files. here we can see we uploaded file.

Step 16 - Check the s3fs status using below commands.

That's it...