How Do We Mount S3 Bucket on Ubuntu 18.04/20.04 using S3FS
S3 bucket is an Object storage service and it's very lowest cost storage option in AWS Cloud. This can be used from the small to big industry-leading data availability, scalability, security, and performance store the data. This post can walk through you how do we mount a S3 bucket object storage in an EC2 instance which running with Ubuntu Operating system. We can an option now, using S3FS package able to do that. the S3FS is a FUSE based file system backed by Amazon S3.
Create an EC2:
Create a new EC2 instance on AWS Cloud with Ubuntu 18.04 or Ubuntu 20.04 version and log in to your istance.
Install Required Packages:
Login to your EC2 instance and Install the required dependencies using the commands below,
$ sudo apt-get update && apt-get install awscli
$ sudo apt-get install automake autotools-dev fuse g++ git libcurl4-gnutls-dev libfuse-dev libssl-dev libxml2-dev make pkg-config
Download and Install s3fs:
Once you have installed the required packages then clone/download the source code from the GitHub and run the script for compiling the package by the commands below,
$ git clone https://github.com/s3fs-fuse/s3fs-fuse.git
$ cd s3fs-fuse
$ sudo make install
Find out the s3fs package on your instance by the command below,
$ which s3fs
Create S3 Bucket:
Create a new S3 bucket on AWS Cloud with set of permission as your required.
Configure Security Credentials:
Create an IAM User account from IAM AWS Cloud resource with necessary IAM policies to the user and generate a Access Key and Secret key.
Before you configure the Security Credentials on your EC2 instance, have to install the AWS-CLI package. We have just few steps available below,
Install the awscli package using the apt command. First, update the packages from the repository and install it by the commands below with -y option,
$ apt-get update
$ sudo apt-get install awscli -y
$ sudo snap install aws-cli
Check the awscli version,
$ aws --version
Note: Seems to be the above one is old version you can download the latest version 2
$ aws configure
AWS Access Key ID [None]: AccessKey
AWS Secret Access Key [None]: SecretKey
Default region name [None]: us-west-2
Default output format [None]: json
You will see the aws credentials details using the command below,
$ cat ~/.aws/credentials
aws_access_key_id = AccessKey
aws_secret_access_key = SecretKey
$ cat ~/.aws/config
region = us-west-2
output = json
Note: Replace the Accesskey, Secretkey and change the region and output (json/text) format as your wish.
The, make sure that are you able to access the S3 buckets from your EC2 instance by aws command with the option "s3 ls"
$ aws s3 ls
Create a file for storing your IAM user credentials to connect with your S3 bucket and to secure the transfer of our object to the S3 bucket.
$ echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > /home/user/.passwd-s3fs
Create a new directory which you need to mount our s3fs agent,
$ sudo mkdir -p /s3-mount/
Execute the command below to mount S3 bccket to the Directory which you have created.
$ sudo s3fs /s3-mount -o passwd_file=/home/user/.passwd-s3fs
Then check your file system to see if it mounts correctly, using the command below.
$ cd /s3-mount
$ echo "First file stores to S3 bucket" > testfile.txt && cat testfile.txt