How to Mount S3 Bucket on Linux (AWS EC2 Instance) Use Case:
Use Case:
AWS S3 is an awesome resource for cloud object storage and the consumption of S3 varies from customer, very common use cases were:
- Backup and Storage – Provide data backup and storage services for others.
- Application Hosting – Provide services that deploy, install, and manage web applications.
- Media Hosting – Build a redundant, scalable, and highly available infrastructure that hosts the video, photo, or music uploads and downloads.
- Software Delivery – Host your software applications that customers can download.
Here I will explain how we implemented S3 in one of our customer.
Customer Requirement:
Solution:
Below are the pre-requisites to install and setup S3fs:
- EC2 instance with root access or sudo access to install S3fs and mount volume
- IAM user which have S3 Full access (For Upload/Download)
- Download latest S3fs package from http://code.google.com/p/s3fs/downloads/list
- update your system to the latest using
yum update all (for CentOS)
- Install below dependencies before installing S3fs package
For CentOS
yum install gcc libstdc++–devel gcc–c++ fuse fuse–devel curl–devel libx
ml2–devel openssl–devel mailcap
For Ubuntu
apt-get install build-essential gcc libfuse-dev libcurl4-openssl-dev libxml2-dev mime-support pkg-config libxml++2.6-dev libssl-dev
Follow the below steps to mount your S3 bucket to your Linux Instance:
Step 1: Download the latest s3fs package and extract:
Step 2: Update OS and install dependencies as mentioned above pre-req.
Step 3: Now change to extracted directory, compile and install s3fs source code.
Step 4: Use the below command to check where s3fs command is placed in O.S. It will also confirm whether the installation is ok:
Step 5: Get IAM user Access and secret key which have appropriate permissions (e.g. S3 Full access), You can get the same from the AWS IAM console
Step 6: Create a new file in /etc with the name passwd-s3fs and Paste the access key and secret key in the below format and change the permission for the file:
Note: Replace AcessKey and SecretKey with original keys.
Step 7: Now create a directory and mount S3bucket in it. Here, Provide your S3 bucket name in place of “your_bucketname”
s3fs your_bucketname -o use_cache=/tmp -o allow_other -o multireq_max=5 /mys3bucket
Replace your_bucket = S3 bucket name which you want to mount
Replace /sravancloudarchS3 = Directory name which you want to mount
Note: At any given point you can unmount this volume using the below command:
Add below Line and save the file:
Now you have successfully mounted your S3 bucket as a Volume in your EC2 instance, any files which you write in /sravancloudarch directory will be replicated to your Amazon S3 bucket.
Hopefully, you enjoyed this post, here are the relevant hands-on video
<>