How to Install and Configure S3FS to Mount an Amazon S3 Bucket on Linux
Introduction
S3FS is a FUSE (Filesystem in Userspace)-based file system that allows you to mount an Amazon S3 bucket as a local directory on a Linux server. Once mounted, applications can seamlessly read from and write to the S3 bucket using standard file system operations, eliminating the need to interact directly with the AWS S3 API. This guide explains how to install S3FS, configure AWS credentials, mount an S3 bucket, and make the mount persistent across system reboots.
Prerequisites
Before installing S3FS, ensure the following requirements are met:
- A Linux server (CentOS/RHEL or a compatible distribution).
- Root or sudo privileges.
- An active AWS account with an existing S3 bucket.
- AWS Access Key ID and Secret Access Key with permissions to access the target S3 bucket.
- FUSE (Filesystem in Userspace) support enabled on the server.
- Internet connectivity to download the required packages and source files.
- A local directory to use as the S3 bucket mount point.
IMPLEMENTATION
FUSE-based file system backed by Amazon S3. Mount an s3 bucket as a local file system to read/write. Since the bucket is mounted as a local file system, the write/read operation is faster than when we read the file from the S3 bucket directly.
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 module:
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
You have successfully installed and configured S3FS to mount an Amazon S3 bucket as a local file system on your Linux server. With the bucket mounted, applications can access S3 objects using standard file operations, making file management simpler and more efficient. To ensure the mount persists after a reboot, add the appropriate entry to the /etc/fstab file. For enhanced security, it is also recommended to restrict permissions on the credentials file (~/.passwd-s3fs) and consider using IAM roles instead of static access keys when running on Amazon EC2 instances.
