Mount AWS S3 Bucket on AWS EC2 [ AWS IAM Role based Authentication]
Mounting an S3 Bucket to Linux: A Step-by-Step Guide
Mounting an S3 bucket to a Linux instance allows you to utilize scalable object storage for large files directly within your file system. This guide will walk you through the process, from installing necessary packages to creating and verifying the mount.
Step 1: Install FUSE Packages
First, you need to install the required FUSE packages. Open your terminal and execute the following command:
yum -y install automake fuse fuse-devel gcc-c++ git libcurl-devel libxml2-devel make openssl-devel
Step 2: Clone the S3FS-FUSE Repository
Next, clone the S3FS-FUSE application from GitHub:
git clone https://github.com/s3fs-fuse/s3fs-fuse
Step 3: Change Directory to the Cloned Repository
Navigate to the cloned directory:
cd s3fs-fuse
Step 4: Build and Install S3FS-FUSE
Run the following commands to build and install S3FS-FUSE:
./autogen.sh
./configure
make
make install
Step 5: Ensure Proper IAM Role Permissions
Make sure you have an IAM role with the appropriate permissions (put, get, and list access to S3).
Step 6: Create the Mount Point
Create a directory to serve as the mount point for your S3 bucket:
mkdir -p /var/s3fs-demo-fs
Step 7: Create the Target S3 Bucket
Create your S3 bucket using the AWS CLI:
aws s3 mb s3://s3fs-demo-bkt
Step 8: Mount the S3 Bucket
Mount the S3 bucket as a filesystem using the following command:
s3fs s3fs-demo-bkt /var/s3fs-demo-fs -o iam_role=ec2-to-s3
Step 9: Verify the Mount
To ensure the S3 bucket is mounted correctly, verify it with the df
command:
df -h /var/s3fs-demo-fs
Step 10: Add an fstab Entry
For persistent mounting across reboots, add an entry to /etc/fstab
:
echo "s3fs#s3fs-demo-bkt /var/s3fs-demo-fs fuse _netdev,allow_other,uid=1002,gid=1002,iam_role=ec2-to-s3,use_cache=/tmp,url=https://s3.us-east-1.amazonaws.com 0 0" >> /etc/fstab
Step 11: Create an Object in the Mounted S3 Bucket
Navigate to the mounted directory and create a new file to test the setup:
cd /var/s3fs-demo-fs
touch "Thanks-for-Watching"
By following these steps, you can successfully mount an S3 bucket to your Linux instance, enabling seamless interaction with S3 storage as if it were a local filesystem.
Comments
Post a Comment