DEV Community

Vikas Prabhu
Vikas Prabhu

Posted on

Harnessing the Power of Amazon S3 as a Mounted Drive: Benefits, Costs, and How-To

Amazon S3 (Simple Storage Service) by Amazon Web Services (AWS) offers a scalable, reliable, and low-latency data storage solution. While typically used for backup and recovery, data archiving, and as a web application storage layer, an innovative approach is to mount S3 as a drive on a server, such as an Ubuntu AWS instance. This post explores the benefits, costs, and provides a step-by-step guide on how to set this up.

Benefits of Using S3 as a Mounted Drive

  • Scalability and Elasticity: Virtually unlimited storage means you can scale up as your data grows without worrying about physical storage limits.
  • Durability and Availability: High durability and availability, with data automatically replicated across multiple devices in multiple facilities.
  • Cost-Effectiveness: Only pay for the storage you use, with no upfront costs or additional expenses for maintaining physical hardware.
  • Accessibility: Simplifies workflows by making it accessible as part of the local file system.
  • Security: Secure data storage with AWS’s robust security model, enhanced by additional encryption and access controls when mounted.
  • Integration and Automation: Seamless integration with other AWS services and automation capabilities.

Costs of Using S3 as a Mounted Drive

  • Storage Costs: Based on the amount of data stored per month and the chosen S3 storage class.
  • Request Costs: Charges for PUT, GET, and other requests, which can add up with frequent file accesses.
  • Data Transfer Costs: Charges for data transferred out of S3, especially significant if transferring to the internet or across AWS regions.
  • Management Overhead: Requires expertise to manage and maintain the setup, consuming administrative resources.

How to Mount an S3 Bucket on Ubuntu

  1. Update Your System:
   sudo apt update && sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode
  1. Install Required Packages: Install s3fs, a FUSE-based file system:
   sudo apt install s3fs -y
Enter fullscreen mode Exit fullscreen mode
  1. Set Up AWS Credentials: Generate access key from aws console with full s3 access.Securely store your AWS credentials:
   mkdir -p $HOME/.aws
   echo YOUR_ACCESS_KEY_ID:YOUR_SECRET_ACCESS_KEY > $HOME/.aws/credentials
   chmod 600 $HOME/.aws/credentials
Enter fullscreen mode Exit fullscreen mode
  1. Create a Mount Point:
   sudo mkdir /mnt/s3bucket
Enter fullscreen mode Exit fullscreen mode
  1. Mount the S3 Bucket:
   sudo s3fs your-bucket-name /mnt/s3bucket -o passwd_file=$HOME/.aws/credentials -o allow_other -o umask=0022
Enter fullscreen mode Exit fullscreen mode
  1. Verify the Mount and Set Automatic Mount on Boot: Ensure the mount is successful and configure it to mount automatically on system reboot:
   ls /mnt/s3bucket
   sudo nano /etc/fstab
Enter fullscreen mode Exit fullscreen mode

Add the following line to /etc/fstab:

   your-bucket-name /mnt/s3bucket fuse.s3fs _netdev,allow_other,passwd_file=/home/ubuntu/.aws/credentials,umask=0022 0 0
Enter fullscreen mode Exit fullscreen mode

Conclusion

Mounting an S3 bucket as a drive on an Ubuntu AWS instance can greatly enhance how you manage and interact with cloud storage. It not only brings the benefits of S3 into a more accessible and traditional file system format but also necessitates careful management to optimize costs. By following the above steps, organizations can effectively integrate Amazon S3 with their existing infrastructure and enjoy the myriad benefits it offers.

Top comments (0)