{"id":6730,"date":"2022-02-04T17:21:01","date_gmt":"2022-02-04T08:21:01","guid":{"rendered":"https:\/\/the-world-star.com\/?p=6730"},"modified":"2026-11-21T12:20:12","modified_gmt":"2026-11-21T03:20:12","slug":"mounting-amazon-s3-as-storage-on-aws-ec2-using-s3fs","status":"publish","type":"post","link":"https:\/\/the-world-star.com\/en\/server\/mounting-amazon-s3-as-storage-on-aws-ec2-using-s3fs-6730\/","title":{"rendered":"Mounting Amazon S3 as Storage on AWS EC2 Using s3fs"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Although I&#039;ve never really written about it before, I&#039;ve recently been using Amazon Web Services (AWS)\u2014the cloud everyone talks about\u2014to run a Minecraft server.<br>It&#039;s so my daughter and I can play Minecraft together. Actually, I needed a server so that either of us could play independently even when the other wasn&#039;t on. And guess what? AWS lets you use their services for free for a whole year!<br>Today&#039;s topic: Mounting S3 as storage on an AWS EC2 instance.<br>Everything is working surprisingly well, so I&#039;m writing this down to keep a record.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u25a0 Background<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><br>My Minecraft world backup files are taking up way too much space.<br>They&#039;re cluttering up the EC2 storage. Looking ahead to when the free tier ends in a year and it starts costing money, I want to keep the EC2 instance itself as compact and low-capacity as possible. I could easily just upgrade the EC2 storage, but apparently, S3 is much cheaper to use.<br>So, I&#039;m trying this out partly as a learning experience.<br>S3 can be slow. Plus, if I put my main game data on S3, constant read\/write access might spike the traffic and increase costs. Let&#039;s just put the backup files on S3.<br>With my usual Unix-like mindset, the idea is to mount S3 and create a symbolic link to the backup directory there.<br>So I did a quick Google search. Oh boy, plenty of guides pop up.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u25a0 Directory Structure Concept<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><br>~\/MinecraftBedRockServer<br>|-worlds<br>|-backup -&gt; link:~\/mnt\/S3_Minecraft\/worlds_backup<br>\/mnt\/S3 ... Newly created, mount S3 here.<br>An S3 bucket dedicated to Minecraft. Since this EC2 instance is exclusively a Minecraft server anyway, maybe just an S3 bucket is fine.<br>|-worlds_backup<br>\u30fbCandidate 1... Rejected<br>~\/mnt\/S3_Minecraft ... Newly created, mount S3 here.<br>An S3 bucket dedicated to Minecraft. Since this EC2 instance is just a Minecraft server, is S3 alone enough?<br>|-worlds_backup<br>\u30fbCandidate 2... Rejected<br>~\/mnt\/s3 ... Newly created, mount S3 here.<br>|-Minecraft ... What if I want to store non-Minecraft files later? Should I use a separate S3 bucket for those?<br>|-worlds_backup<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u25a0 References for Mounting S3<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><br>Candidate 1: Mounting tool: goofys ... Apparently, this one is faster.<br>https:\/\/www.acrovision.jp\/service\/aws\/?p=797<br>1. Create an S3 bucket named: S3_Minecraft<br>2. Create an IAM role so the software can access it. Same as the role I created when accessing S3 from WordPress.<br>\u3000 Set it to AmazonS3FullAccess.<br>3. Install various dependencies for goofys?<br>Install what&#039;s needed.<br>\u25a0 Git<br>\u25a0 golang<br>\u25a0 goofys<br>Here are the commands to run:<br>$ sudo yum -y install golang fuse git<br>$ export GOPATH=$HOME\/go<br>$ go get github.com\/kahing\/goofys<br>$ go install github.com\/kahing\/goofys<br>\u3000\u2026Rejected this because the name of the alternative option below sounded better.<br>\u25a0 Candidate 2: Mounting tool: s3fs<br>\u3000\u3000\u2026I went with this one because the name sounded more fitting for the job.<br>\u3000\u3000Apparently, this one is slower though.<br>https:\/\/qiita.com\/latin1\/items\/aade223be36a87cbe538<br>I&#039;d hate it if this were exclusive to Amazon Linux.<br>Wait, I&#039;m using Ubuntu. Let me search for that, and sure enough, guides exist.<br>https:\/\/qiita.com\/taito273\/items\/17e469373478ff38a200<br>0. Prepare S3 Bucket<br>Named minecraft-nyanpu. No uppercase letters. No underscores. Globally unique.<br>1. Create an IAM user<br>\u3000 Set it to AmazonS3FullAccess.<br>An Access Key ID and Secret Access Key will be displayed, so make sure to save them.<br>\u3000 The reference URL creates it from a group, but creating a USER is fine, right?<br>I set it up the same way as my WordPress exercise.<br>Named it s3user.<br>Apparently, you can also use an IAM Role. Installing s3fs...<br>2. Installing s3fs<br>Pull from GitHub and build.<br>For Ubuntu, use the usual apt-get.<br>sudo apt-get install automake autotools-dev g++ git libcurl4-gnutls-dev libfuse-dev libssl-dev libxml2-dev make pkg-config<br>Grab the s3fs code, build it, and install.<br>$ git clone https:\/\/github.com\/s3fs-fuse\/s3fs-fuse.git<br>$ cd s3fs-fuse<br>$ .\/autogen.sh<br>$ .\/configure<br>$ make<br>$ sudo make install<br>Usage of \/: 92.6% of 7.69GB Users logged in: 0<br>Disk space is getting tight...<br>After installing, I removed the GitHub repository files.<br>Ran rm -r on s3fs as well.<br>Then cleared the cache with sudo apt-get clean.<br>Usage of \/: 90.4% of 7.69GB Users logged in: 0<br>\u25a0 Create Mount Point<br>$ sudo mkdir \/mnt\/s3<br>\u25a0 Save IAM Access Key<br>$ echo &lt;AccessKeyID&gt;:&lt;SecretAccessKey&gt; | sudo tee -a \/etc\/passwd-s3fs<br>$ sudo chmod 640 \/etc\/passwd-s3fs<br>\u25a0 Mount<br>sudo s3fs &lt;bucket-name&gt; &lt;mount-point&gt; -o rw,allow_other,uid=&lt;UID&gt;,gid=&lt;GID&gt;,default_acl=public-read<br>In practice, it looks like this:<br>sudo s3fs minecraft-nyanpu \/mnt\/s3 -o rw,allow_other,uid=1000,gid=1000,default_acl=public-read<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u25a0 Wait, there&#039;s no auto-mount on startup!<br><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Was it editing fstab?<br>s3fs#bucketname \/share fuse auto,rw,allow_other,use_cache=\/tmp,uid=222,gid=500 0 0<br># Wait, isn&#039;t that a comment?<br># echo &quot;s3fs#testubuntusvr01data \/mnt\/objstorage\/data fuse nonempty,allow_other,url=http:\/\/inter-st.gmocloud.com,passwd_file=\/etc\/s3fs\/s3fspasswd 0 0&quot; &gt;&gt; fstab<br>s3fs#[bucket-name] [directory-to-mount] fuse allow_other,use_cache=\/tmp,uid=[UID],gid=[GID],passwd_file=\/etc\/passwd-s3fs 0 0<br>s3fs#[bucket-name]... doesn&#039;t that look weird? Guess it&#039;s fine.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u25a0 Result<br><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The mount was successful, and I could view directories, navigate them, and read files, but writing or creating new files wasn&#039;t working.<br>I tried enabling S3 ACLs and various other tweaks, but nothing worked.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u25a0 Tried rebooting.<br><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The next day, having run a mob trap continuously for three days in Minecraft, my CPU credits had dropped to zero.<br>Previously, the load wasn&#039;t high enough to consume CPU credits, but after removing a stray torch, spawn rates increased and it seems the load went into the negative.<br>Since my CPU credits were practically at zero anyway, I decided to reboot the server.<br>I rebooted after credits recovered to 17, but they stayed at 17. When you&#039;re above 30 it drops down to 30, but it doesn&#039;t look like it accumulates back up past 30.<br>The S3 mount defined in fstab mounted successfully. And for some reason, file writing, which hadn&#039;t worked before, started working.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u25a0 Probable Cause<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><br>1. Command line failed, but fstab succeeded.<br>2. Thanks to enabling S3 ACLs, maybe there was a propagation delay or a reboot was required?<br>\u3000My WordPress exercise was similar\u2014it just magically started working out of nowhere.<br>I&#039;ll try disabling ACLs later and see what happens.<br>\/\/ Logs below<br>Welcome to Ubuntu 20.04.3 LTS (GNU\/Linux 5.11.0-1028-aws x86_64)<br>* Documentation: https:\/\/help.ubuntu.com<br>* Management: https:\/\/landscape.canonical.com<br>* Support: https:\/\/ubuntu.com\/advantage<br>System information as of Fri Feb 4 13:17:59 JST 2022<br>System load: 1.04 Processes: 124<br>Usage of \/: 77.7% of 7.69GB Users logged in: 0<br>Memory usage: 19% IPv4 address for eth0: 172.31.45.138<br>Swap usage: 0%<br>* Ubuntu Pro delivers the most comprehensive open source security and<br>compliance features.<br>https:\/\/ubuntu.com\/aws\/pro<br>26 updates can be applied immediately.<br>To see these additional updates run: apt list --upgradable<br>Last login: Fri Feb 4 10:05:08 2022 from 121.103.0.23<br>ubuntu@ip-172-31-45-138:~$ mount<br>\/dev\/xvda1 on \/ type ext4 (rw,relatime,discard)<br>devtmpfs on \/dev type devtmpfs (rw,relatime,size=489256k,nr_inodes=122314,mode=755,inode64)<br>sysfs on \/sys type sysfs (rw,nosuid,nodev,noexec,relatime)<br>:<br>Omitted<br>:<br>\/var\/lib\/snapd\/snaps\/snapd_14549.snap on \/snap\/snapd\/14549 type squashfs (ro,nodev,relatime,x-gdu.hide)<br>s3fs on \/mnt\/s3 type fuse.s3fs (rw,relatime,user_id=0,group_id=0,allow_other) .....Successfully mounted<br>tmpfs on \/run\/user\/1000 type tmpfs (rw,nosuid,nodev,relatime,size=99172k,mode=700,uid=1000,gid=1000,inode64)<br>tmpfs on \/run\/snapd\/ns type tmpfs (rw,nosuid,nodev,size=99176k,mode=755,inode64)<br>ubuntu@ip-172-31-45-138:~$ ls \/mnt\/s3<br>levelname.txt world_icon.jpeg worlds_backup<br>ubuntu@ip-172-31-45-138:~$ touch \/mnt\/s3\/xxx ... Try creating a file named &quot;xxx&quot;<br>ubuntu@ip-172-31-45-138:~$ ls<br>HowToUseRemoteXonSsh.txt MinecraftServerBedrock<br>ubuntu@ip-172-31-45-138:~$ ls \/mnt\/s3<br>levelname.txt world_icon.jpeg worlds_backup xxx ... File &quot;xxx&quot; was successfully written<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u25a0 Testing and Verification<br><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Since we&#039;re at it, let&#039;s test things out.<br>1. Is it a difference between the command line and fstab?<br>------<br>Unmount and try mounting via the command line again.<br>ubuntu@ip-172-31-45-138:~$ sudo umount \/mnt\/s3<br>ubuntu@ip-172-31-45-138:~$ ls \/mnt\/s3<br>ubuntu@ip-172-31-45-138:~$ sudo s3fs minecraft-nyanpu \/mnt\/s3 -o rw,allow_other,uid=1000,gid=1000,default_acl=public-read<br>ubuntu@ip-172-31-45-138:~$ ls \/mnt\/s3<br>levelname.txt world_icon.jpeg worlds_backup xxx<br>ubuntu@ip-172-31-45-138:~$ touch \/mnt\/s3\/xxx2<br>touch: failed to close &#039;\/mnt\/s3\/xxx2&#039;: Operation not permitted<br>ubuntu@ip-172-31-45-138:~$<br>-----<br>It fails.<br>Seems like the command line method is the issue.<br>2. Revert ACL to disabled, reboot, and test fstab<br>levelname.txt world_icon.jpeg worlds_backup xxx<br>ubuntu@ip-172-31-45-138:~$ touch \/mnt\/s3\/xxx2<br>ubuntu@ip-172-31-45-138:~$<br>ubuntu@ip-172-31-45-138:~$<br>ubuntu@ip-172-31-45-138:~$ ls \/mnt\/s3<br>levelname.txt world_icon.jpeg worlds_backup xxx xxx2<br>ubuntu@ip-172-31-45-138:~$<br>It worked.<br>Conclusion: Only the fstab configuration works properly.<br>Is the command-line method bugged? Or were the arguments wrong?<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u25a0 Using It for the Real Backup<br><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">ln -s \/mnt\/s3\/worlds_backup worlds\/backup<br>Modify the backup shell script<br>so that backup files are saved under worlds\/backup\/.<br>Start the Minecraft script and wait until backup time.<br>Checked the S3 console: OK<br>Confirmed that files are being created via the command line: OK<br>ubuntu@ip-172-31-45-138:~\/MinecraftServerBedrock$ ls -l worlds\/backup\/<br>total 2065875<br>-rw-rw-r-- 1 ubuntu ubuntu 92340073 Feb 4 07:00 mc_backup_hourly_20220204-070002.tar.gz<br>-rw-rw-r-- 1 ubuntu ubuntu 92343777 Feb 4 07:30 mc_backup_hourly_20220204-073001.tar.gz<br>-rw-rw-r-- 1 ubuntu ubuntu 92443911 Feb 4 08:00 mc_backup_hourly_20220204-080001.tar.gz<br>-rw-rw-r-- 1 ubuntu ubuntu 92561005 Feb 4 08:30 mc_backup_hourly_20220204-083001.tar.gz<br>-rw-rw-r-- 1 ubuntu ubuntu 92660318 Feb 4 09:00 mc_backup_hourly_20220204-090001.tar.gz<br>-rw-rw-r-- 1 ubuntu ubuntu 92779749 Feb 4 09:30 mc_backup_hourly_20220204-093001.tar.gz<br>-rw-rw-r-- 1 ubuntu ubuntu 92670514 Feb 4 10:00 mc_backup_hourly_20220204-100001.tar.gz<br>-rw-rw-r-- 1 ubuntu ubuntu 92435645 Feb 4 14:00 mc_backup_hourly_20220204-140001.tar.gz<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u25a0 Now that capacity has increased (since storage limits are no longer an issue?), I could extend the backup retention period, but<br>30-minute backups are just for rolling back in case of accidental death, so they probably aren&#039;t necessary long-term.<br>Instead, maybe I should bring back daily backups and keep them for about a week?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Although I&#039;ve never really written about it before, I&#039;ve recently been using Amazon Web Services (AWS)\u2014the cloud everyone talks about\u2014to run a Minecraft server.It&#039;s so my daughter and I can play Minecraft together. Actually, I needed a server so that either of us could play independently even when the other wasn&#039;t on. And guess what? [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2606,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/175.41.248.22\/?p=1450","_lightning_design_setting":{"layout":"default"},"footnotes":""},"categories":[3],"tags":[69,70,119,1254,67,68],"class_list":["post-6730","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-ec2","tag-aws","tag-s3","tag-infrastructure","tag-server","tag-wordpress","en-US"],"_links":{"self":[{"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/posts\/6730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/comments?post=6730"}],"version-history":[{"count":1,"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/posts\/6730\/revisions"}],"predecessor-version":[{"id":6731,"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/posts\/6730\/revisions\/6731"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/media\/2606"}],"wp:attachment":[{"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/media?parent=6730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/categories?post=6730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/the-world-star.com\/wp-json\/wp\/v2\/tags?post=6730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}