- DevOpsCube Newsletter
- Posts
- Mounting S3 Using fstab
Mounting S3 Using fstab
👋 Hi! I’m Bibin Wilson. In each edition, I share practical tips, guides, and the latest trends in DevOps and MLOps to make your day-to-day DevOps tasks more efficient. If someone forwarded this email to you, you can subscribe here to never miss out!
In today’s edition, we’ll take a look at the recently added support for fstab-based mounting in the S3 File Client.
Mounting s3 Buckets to ec2
Mounting S3 to instances is a common approach for sharing data and configurations.
For instance, you can keep large datasets in S3 for machine learning or analytics tasks and access them directly from your instance, skipping the need to download everything beforehand.
It's also widely used in ETL workflows.
This setup is usually handled using the Mountpoint for Amazon S3 client.
Mountpoint for Amazon S3 (File Client)
Mountpoint for Amazon S3 is a high-throughput, open-source file client that allows your applications to connect to Amazon S3 buckets and access S3 objects as if they were files in a local file system.
In short, here is what it does.
It acts as an intermediary, translating standard file system operations (like open, read, write, list directory) from your applications into S3 API calls (like GET, PUT, LIST → REST based API over HTTPS).
Mounting a bucket to ec2 is as simple as,
mount-s3 bucket-name /path/to/mount
For Mountpoint for S3 to work properly, the EC2 instance must have an IAM role that grants basic read and write permissions to the S3 bucket.
Usually, S3 mounting on instances is handled either through a user data script or by setting up a systemd service that runs the client’s mount command.
This ensures the mount persists even after the instance is rebooted.
S3 Mount With fstab (New)
The fstab (short for file systems table) is a file in Linux and Unix systems that tells the system which storage devices or filesystems to mount automatically when the server starts up. It’s located at /etc/fstab.

Mountpoint for Amazon S3 now supports automatic mounting of S3 buckets using the standard Linux fstab file.
This makes it easier to set up persistent mounts for your S3 buckets on EC2 instances.
By adding a simple entry to fstab, your S3 buckets will mount automatically whenever the instance boots, just like local drives or network file systems like EBS or NFS.
The best part is that this approach follows familiar Linux system admin practices, making mount management more consistent and centralized.
Hands on Example
I tried mounting an S3 bucket using fstab on an EC2 instance, and it worked flawlessly.
You can follow the steps below to test it yourself.
First, launch an EC2 instance with an IAM role that has the necessary permissions to access the S3 bucket.
Once the instance is up and running, log in to it and open the fstab file:
sudo vi /etc/fstab
Create a mount directory for the bucket using the following command:
sudo mkdir -p /mnt/s3-bucket
Add the following line to the fstab file and save it. In this example, dcmount
is the S3 bucket name, and /mnt/s3-bucket
is the local mount path. Make sure to replace these with your actual bucket name and desired mount location:
s3://dcmount/ /mnt/s3-bucket mount-s3 _netdev,nosuid,nodev,nofail,rw 0 0
Now test the mount using the following command:
sudo mount -a
On a successful mount you will get the following message.
bucket dcmount is mounted at /mnt/s3-bucket
In real-world scenarios, you'll often want to automate the fstab entry using EC2 user data scripts. This is especially important since most deployments use pre-configured AMIs, and instances are launched as part of an automated pipeline.
Here's a simple tested shell script you can use in your EC2 user data to add the fstab entry at launch time.
#!/bin/bash
S3_BUCKET_NAME="dcmount"
MOUNT_POINT="/mnt/s3-bucket"
FSTAB_ENTRY="s3://${S3_BUCKET_NAME}/ ${MOUNT_POINT} mount-s3 _netdev,nosuid,nodev,nofail,rw 0 0"
sudo mkdir -p "${MOUNT_POINT}"
if ! grep -q "s3://${S3_BUCKET_NAME}.*${MOUNT_POINT}" /etc/fstab; then
echo "Adding S3 mount to /etc/fstab"
echo "${FSTAB_ENTRY}" | sudo tee -a /etc/fstab
else
echo "S3 mount entry already exists in /etc/fstab"
fi
What did you think of todays email?Your feedback helps me create better guides for you! |
Reply