Tuesday, March 14, 2017

Procedure: Mount S3 Bucket on AWS EC2 Instance

A quick handy how-to:


How to mount S3 bucket on EC2 instance of AWS

S3FS is the S3 file system that will be required here.

Firstly update the packages on Ubuntu machine

Step 1:


# sudo apt-get install build-essential git libfuse-dev libcurl4-openssl-dev libxml2-dev mime-support automake libtool
# sudo apt-get install pkg-config libssl-dev
# git clone https://github.com/s3fs-fuse/s3fs-fuse
# cd s3fs-fuse/
# ./autogen.sh
# ./configure --prefix=/usr --with-openssl
# make
# sudo make install

Step 2:


S3FS needs AWS access key id and secret key to work. Create "passwd-s3fs" file at /etc/passwd-s3fs with content

<AWS Access Key ID>:<AWS Secret Access Key>

Step 3: Change permission


# chmod 640 /etc/passwd-s3fs

Step 4: Create mountpoint:


# mkdir <mount_point>

Step 5: Now mount the s3 bucket


# sudo s3fs bucketname /mys3bucket

Step 6: To check mounted s3 bucket


# df -Th /mys3bucket

# mkdir /mys3bucket

In most cases, you will want S3 to be mounted automatically after each reboot. So, add below line to /etc/fstab

# s3fs#<buket_name> /mys3bucket fuse allow_other,use_cache=/tmp/cache 0 0

For istance: s3fs#jarvis.pc /mys3bucket fuse allow_other,use_cache=/tmp/cache 0 0