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.

FAQs

1. What is s3fs?
s3fs is a FUSE-based file system that allows you to mount an Amazon S3 bucket as a local file system on a Linux server.

2. How do you mount an S3 bucket using s3fs?
Install and configure s3fs with AWS credentials, create a local mount point, and use the s3fs command to mount the S3 bucket.

3. How can you automatically mount an S3 bucket after reboot?
Add the appropriate s3fs entry to /etc/fstab so the S3 bucket can be mounted automatically when the server starts.

How to Create an AWS S3 Bucket Using Terraform

How to Mount Amazon S3 bucket as a Drive

Talk to our experts

Looking for the right technology solution for your business?. Our experts can help with web hosting, domain registration, DevOps and cloud, software development, web applications, mobile applications, and enterprise solutions. Get in touch with our team here.

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Reply

Scroll to Top