An S3 Bucket is similar to an NFS share in that it is a mountable storage volume.
This assumes you have a running Linux EC2 Instance. If youre EC2 instance is using the Amazon 2 image, install epel.
sudo amazon-linux-extras install epel
Then install the S3FS FUSE package. This will create the /etc/fuse.conf file.
sudo yum install s3fs-fuse
On the other hand, if you are running Amazon Linux 2023 (AL2023) . . .
~]$ cat /etc/amazon-linux-release
Amazon Linux release 2023 (Amazon Linux)
Use these commands.
sudo yum install automake fuse fuse-devel gcc-c++ git libcurl-devel libxml2-devel make openssl-devel -y
git clone https://github.com/s3fs-fuse/s3fs-fuse.git
cd s3fs-fuse
./autogen.sh
./configure --prefix=/usr --with-openssl
make
sudo make install
Next you will need to grab one of your IAM (Identity and Access Management) Access Key and Secret Key.
AVOID TROUBLE
The Secret Key is only available to you when you create a new IAM user, so if you don't have the Secret Key, you may need to Create IAM Access Keys using the AWS CLI.
On your EC2 Instance, create a file named .passwd-s3fs and append your IAM Access Key and Secret Key to the .passwd-s3fs file.
echo <your access key ID>:<your secret key> > ${HOME}/.passwd-s3fs
Set the permissions of the .passwd-s3fs so that only the owner of the file has read and write permission to the .passwd-s3fs file.
chmod 0600 $HOME/.passwd-s3fs
Create directory for where your S3 Bucket will be mounted.
mkdir /usr/local/my-bucket-abcdefg
Use the s3fs command to mount the S3 Bucket.
s3fs my-bucket-abdcefs /usr/local/my-bucket-abdcefs -o passwd_file=${HOME}/.passwd-s3fs
The mount command can then be used to validate that the S3 Bucket has been mounted.
~]$ mount | grep test
s3fs on /usr/local/my-bucket-abcdefg type fuse.s3fs (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
Better yet, an entry like this can be added to /etc/fstab so that the S3 Bucket is mounted when the Operating System is rebooted.
s3fs#my-bucket-abcdefg /usr/local/aws/my-bucket-abcdefg fuse.s3fs passwd_file=/home/john.doe/.passwd-s3fs 0 0
However, when I tried adding an entry like this in my CentOS VM /etc/fstab, the VM would go into emergency mode on boot. So I removed the entry from /etc/fstab and created a simple bash script that uses the s3fs command to mount the S3 bucket and then I added an entry like this to crontab to run the bash script 60 seconds after boot to mount the S3 Bucket.
@reboot sleep 60 && bash /usr/local/scripts/mount_s3_bucket.sh
If this is an empty S3 Bucket, you can create a new file in the Bucket.
~]$ echo "Hello World" > /usr/local/my-bucket-abcdefg/example.txt
Did you find this article helpful?
If so, consider buying me a coffee over at