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:
* AWS Access Key ID
* Secret Access Key
Name of bucket you want mount
Read/Write permissions to bucket
You will get AWS Access Credentials when you create a IAM user. We need those credentials with essential permissions
to successfully mount s3 bucket
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
sudo apt-get install automake autotools-dev g++ git libcurl4-gnutls-dev libfuse-dev libssl-dev libxml2-dev make pkg-config
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
git clone https://github.com/s3fs-fuse/s3fs-fuse.git cd s3fs-fuse ./autogen.sh ./configure make sudo make install
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.
# echo AWS_ACCESS_KEY_ID:AWS_SECRET_ACCESS_KEY > ~/.passwd-s3fs # chmod 600 ~/.passwd-s3fs
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.
s3fs mybucket /path/to/mountpoint -o passwd_file=/path/to/passwd
If you encounter any errors, enable debug output:
s3fs mybucket /path/to/mountpoint -o passwd_file=/path/to/passwd -d -d -f -o f2 -o curldbg
You can also mount on boot by entering the following line to
s3fs#mybucket /path/to/mountpoint fuse _netdev,allow_other 0 0
mybucket /path/to/mountpoint fuse.s3fs _netdev,allow_other 0 0
You can have a global credential file at /etc/passwd-s3fs
echo MYIDENTITY:MYCREDENTIAL > /etc/passwd-s3fs chmod 600 /etc/passwd-s3fs
If you are mounting on boot, you may also need to make sure
netfs service is start on boot