Mounting AWS S3 Bucket on Amazon EC2 Linux Using S3FS

Mounting AWS S3 Bucket on Amazon EC2 Linux Using S3FS

Project Description

This hands-on project involves mounting an AWS S3 bucket onto an Amazon EC2 Linux instance using S3FS. This project provides a practical introduction to Amazon Web Services (AWS), specifically Amazon S3 (Simple Storage Service) and Amazon EC2 (Elastic Compute Cloud), as well as S3FS, a FUSE-based file system.

Step 1: Create a New IAM User

First, log in to the AWS Management Console and navigate to the IAM service. Then, under "Users," click "Add user" and enter a username.

Step 2: Attach Policies to the User

During user creation, select "Attach Policies directly" and click on "Create Policy." Create a new policy with the settings mentioned below, focusing on S3-related actions:

  • For Service, choose S3

  • Under Actions Allowed : Choose "ListAllMyBuckets", "ListBucket", "ListBucketVersions", "GetObject", "GetObjectVersion", "PutObject"

  • Under Resources: Choose Specific. Then tick "Any" on Bucket and Object

Step 3: Review and Create

After creating the policy, give it a suitable name and proceed to create the IAM user, attaching the newly created policy to the user.

Step 4: Get Access Keys

Once the user is created, go to "Security Credentials," and under "Access Keys," click on "Create Keys." Choose "Command Line Interface (CLI)" and get the Access Key and Secret Key.

Step 5: Launch an EC2 Instance

Step 6: Install AWS CLI On the Instance

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Step 7: Install S3FS On the EC2 Instance

sudo apt install s3fs -y

Step 8: Create a Folder and Add Files

Create a folder named "bucket" at a location /home/ubuntu on the EC2 instance. Add 2–3 files to this folder.

mkdir bucket

touch test1.txt test2.txt test3.txt

Step 9: Create S3 Bucket

Go to the S3 dashboard and click on "Create bucket". Enter a name for your bucket.

Step 10: Configure AWS CLI

On the EC2 instance, configure the AWS CLI by running the command aws configure and providing the Access Key and Secret Key obtained earlier.

Step 11: Sync Files to S3 Bucket

Run the below command to sync the files from the given location on the EC2 instance to the S3 bucket.

aws s3 sync /home/ubuntu/bucket s3://devopschallenge-day89-s3-bucket

Step 12: Verify the Sync

Go to your S3 bucker to confirm that all the files from the EC2 instance are successfully uploaded to the S3 bucket.

Thank you for reading.