How to mount AWS S3 bucket on linux

amazon AWS is offering amazing clound storange service called s3(Simple Storange Service). It is fast and cheap and can
be configured with AWS CDN(Content Delivery Network). It work in such a way that, it containts top level directory like things called
buckets. Buckets can have both files and directories. If you are often working with S3 is would be useful to mount AWS S3 bucket on
your machine or EC2 instance. So, once you mount AWS s3 bucket. You can use it like any other hard disk or partition.

Requirements to mount S3 bucket:

Access Credentials

* AWS Access Key ID
* Secret Access Key

Name of bucket you want mount
Read/Write permissions to bucket
s3fs-fuse

You will get AWS Access Credentials when you create a IAM user. We need those credentials with essential permissions
to successfully mount s3 bucket

Install s3fs

We will use s3fs-fuse software to mount s3 bucket. To get strted install s3fs on machine either using package manager or compiling it from source.
In this article, we will install it from the source.

Dowload or clone s3fs-fuse from github

Before we install s3fs, make sure that you have all dependencies. Install the following dependencies
On debian/ubuntu

sudo apt-get install automake autotools-dev 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

Clone the repository (To clone you need software git. If you don’t have git you can download from here)

Let’s clone, compile and install s3fs

Mount AWS S3 bucket

If you install s3fs successfully, you can now mount AWS S3  bucket as a disk or partition. To do so, you need AWS Access credentials. If you don’t have them you can create the one by creating IAM user AWS IAM  or you can ask your administrator for Access Credentials. Once you have them put them into a file as AWS_ACCESS_KEY_ID:AWS_SECRET_ACCESS_KEY.  You can write these credentials to a hidden file in home directory.

Change permission just to make sure only you can access.

Finally, mount your bucket using following commands.

Create a mount directory where you will mount the bucket. Get the bucket name.

If you encounter any errors, enable debug output:

You can also mount on boot by entering the following line to /etc/fstab

or

You can have a  global credential file at /etc/passwd-s3fs

If you are mounting on boot, you may also need to make sure netfs service is start on boot

😉

Leave a Reply

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