How to Mount an Amazon S3 Bucket as a Local File System Using s3fs

Introduction

s3fs is a FUSE-based file system backed by Amazon S3. It allows you to mount an S3 bucket as a local file system so that you can read and write files using standard file system operations.

Since the S3 bucket is mounted as a local file system, applications can access the bucket using normal file system commands instead of directly interacting with the S3 API.

Prerequisites

Before proceeding, make sure you have:

  • A Linux server with root or sudo access.
  • An active Amazon S3 bucket.
  • AWS Access Key and Secret Key with the required permissions.
  • Internet connectivity from the server.
  • Sufficient permissions to install packages and kernel modules.
  • A local directory to use as the S3 mount point

Implementation

Install Dependencies:

yum install gcc libstdc++-devel gcc-c++ curl-devel libxml2-devel openssl-devel mailcap util-linux

Download fuse:

wget http://sourceforge.net/projects/fuse/files/fuse-2.X/2.9.4/fuse-2.9.4.tar.gz

Extract and install it:

cd fuse-2.9.4

./configure --prefix=/usr/local

make

make install

Add to loadable modules:

ldconfig

modprobe fuse

Download s3fs:

wget https://s3fs.googlecode.com/files/s3fs-1.74.tar.gz

Extract and install it:

tar -xzf s3fs-1.74.tar.gz

cd s3fs-1.74

./configure --prefix=/usr/local

make

make install

Export the access key and secret key:

echo AccessKey:Secretkey > ~/.passwd-s3fs

Install fuse:

yum install libfuse,fuse-libs

Mount the bucket to a local directory.

s3fs -o allow_other -o use_cache=/tmp/cache/ bucket-name /mnt/

where,

/tmp/cache – local cache directory.

bucket-name – S3 bucket Name

/mnt – Local Mount point

Add a permanent entry in /etc/fstab

s3fs#bucket-name /cfmnt fuse allow_other,use_cache=/tmp/cache 0 0

Conclusion

By following the above steps, you can install FUSE and s3fs and mount an Amazon S3 bucket as a local file system. Once mounted, the S3 bucket can be accessed through the specified local mount point using standard file system operations. Adding the entry to /etc/fstab also allows the bucket to be mounted automatically when the server starts.

admin

Writes about Cloud & AWS at Pheonix Solutions.

Leave a Reply

Scroll to Top