shaibaz Badai
shaibaz Badai

Reputation: 32

AWS S3 bucket is not remounting after restarting EC2 Instance

I mounted my S3 bucket to my EC2 Instance using S3fs, and I was able to read, write to my S3 bucket. But after restarting my EC2 Instance, S3 bucket is automatically unmounted. I found that to make it persistent and automatically mount for every reboot we need to add below entries to /etc/rc.local

/usr/bin/s3fs myS3bucket -o use_cache=/tmp -o allow_other -o multireq_max=5 /myS3bucket

But still It is not mounting on reboot.

Upvotes: 1

Views: 2295

Answers (2)

Suresh Kumar
Suresh Kumar

Reputation: 712

I was able to make it work by running it as systemd service.

  • Create Service File - /usr/lib/systemd/system/mybucket-mount.service

    [Unit]
    Description = Mount S3 Bucket my-bucket
    Wants=network-online.target
    After=network.target network-online.target
    
    [Service]
    Type=oneshot
    RemainAfterExit=yes
    ExecStart = /usr/bin/s3fs my-bucket /MyBucketMount/ -o uid=500,gid=501,iam_role=MyRole,use_cache=/tmp,endpoint=ap-south-1,url=https://s3.amazonaws.com
    ExecStop=/bin/umount /MyBucketMount/
    
    [Install]
    WantedBy = multi-user.target
    
  • Create Link

    ln  -sf /usr/lib/systemd/system/mybucket-mount.service /etc/systemd/system/multi-user.target.wants/mybucket-mount.service
    
  • Enable Service

    systemctl enable mybucket-mount.service
    
  • Start Service

    systemctl start mybucket-mount.service
    

Upvotes: 0

Mike Doe
Mike Doe

Reputation: 17576

Did you went through the official documentation?

You can also mount on boot by entering the following line to /etc/fstab:

s3fs#mybucket /path/to/mountpoint fuse _netdev,allow_other 0 0

or

(…)

Note2: You may also need to make sure netfs service is start on boot

A network mount requires a network access in the first place.

Upvotes: 1

Related Questions