Skip to content

Instantly share code, notes, and snippets.

@VioletVivirand
Last active February 17, 2025 02:48
Show Gist options
  • Save VioletVivirand/f596afc4020bcd08c817c83a36411359 to your computer and use it in GitHub Desktop.
Save VioletVivirand/f596afc4020bcd08c817c83a36411359 to your computer and use it in GitHub Desktop.
Mount S3 Bucket on Startup with Mountpoint for Amazon S3

Mount S3 Bucket on Startup with Mountpoint for Amazon S3

Tested on Amazon S3 with Amazon Linux 2023.

References

systemd Service template

[Unit]
Description=Mountpoint for Amazon S3 mount
After=cloud-init.target
AssertPathIsDirectory=<mountpath>

[Service]
Type=forking
User=<username>
Group=<groupname>
ExecStart=/usr/bin/mount-s3 <bucketname> <mountpath>
ExecStop=/usr/bin/fusermount -u <mountpath>

[Install]
WantedBy=default.target

Please fill in the following variables:

  • <username>: Get by executing whoami
  • <groupname>: Get by executing id -Gn $(whoami)
  • <bucketname>: The name of your bucket
  • <mountpath>: The path you gonna mount the bucket, remember to create the directory before enabling this service by executing mkdir <mount path>, such as mkdir ~/mnt

Usage

Be sure to install mouintpoint-s3. Then:

  1. Create the systemd service and placed it into /etc/systemd/system/, e.g., /etc/systemd/system/mountpoint-s3.service
  2. Start the service to verify if it works: systemctl start mountpoint-s3
  3. If it works, make it start automaticlly on startup: systemctl enable mountpoint-s3

Also consider to modify the mount-s3 command in ExecStart part if any additional option should be appended to it (e.g., /usr/bin/mount-s3 <bucket name> <mount path> --allow-delete to allow delete action).

Enjoy!

[Unit]
Description=Mountpoint for Amazon S3 mount
After=cloud-init.target
AssertPathIsDirectory=<mountpath>
[Service]
Type=forking
User=<username>
Group=<groupname>
ExecStart=/usr/bin/mount-s3 <bucketname> <mountpath>
ExecStop=/usr/bin/fusermount -u <mountpath>
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment