Photo by Arian Darvishi on Unsplash
Project-10: Mounting AWS S3 Bucket On Amazon EC2 Linux Using S3FS
Day 89: #90DaysOfDevOps Challange
What is S3FS?
S3FS is a FUSE filesystem that allows you to mount an Amazon S3 bucket as a local filesystem. This means that you can access your S3 bucket files as if they were stored locally on your computer.
Why would you want to do this?
There are a few reasons why you might want to mount an S3 bucket as a local filesystem. For example, you might want to:
Access your S3 bucket files more quickly.
Use local filesystem tools to manage your S3 bucket files.
Share your S3 bucket files with other users on your local network.
How do I mount an S3 bucket as a local filesystem?
To mount an S3 bucket as a local filesystem, you will need to follow these steps:
Create an EC2 server.
Create an IAM user with programmatic access.
Create a credential file for S3FS.
Run the
sudo s3fs
command to mount the S3 bucket.Verify that the S3 bucket is mounted by running the
mount
command.
Here are the steps in detail:
- Create an EC2 server.
In the AWS console, create an EC2 instance. You can use any Linux AMI that you want.
- Create an IAM user with programmatic access.
In the IAM console, create an IAM user with programmatic access. Give the user the following permissions:
AmazonS3FullAccess
AmazonS3ReadOnlyAccess
- Create a credential file for S3FS.
Create a file called .passwd-s3fs
in your home directory. The file should contain the following line:
AWS_ACCESS_KEY_ID:AWS_SECRET_KEY_ID
Replace AWS_ACCESS_KEY_ID
and AWS_SECRET_KEY_ID
with your IAM user's access key ID and secret access key.
- Run the
sudo s3fs
command to mount the S3 bucket.
Run the following command to mount the S3 bucket as a local filesystem:
sudo s3fs bucketname /path/to/mount -o passwd_file=.passwd-s3fs,nonempty,rw,allow_other
Replace bucketname
with the name of your S3 bucket and /path/to/mount
with the path to the directory where you want to mount the S3 bucket.
- Verify that the S3 bucket is mounted by running the
mount
command.
Run the following command to verify that the S3 bucket is mounted:
mount
You should see the S3 bucket listed in the output of the mount
command.
That's it! You have now successfully mounted an S3 bucket as a local filesystem.
Here are some additional tips:
You can use the
fstab
file to make the S3 bucket mount persistent after a reboot.You can use the
-o url
option to specify the endpoint for your S3 bucket.You can use the
-o use_path_request_style
option to enable path-style requests for your S3 bucket.
I hope this blog post has helped you to understand how to mount an S3 bucket as a local filesystem. If you have any questions, please feel free to leave a comment below.๐