Mounting an AWS S3 Bucket on an Amazon EC2 Linux Instance Using S3FS

Mounting an AWS S3 Bucket on an Amazon EC2 Linux Instance Using S3FS

Mounting an AWS S3 bucket on an Amazon EC2 instance can simplify data management by allowing you to interact with S3 data as if it were on a local filesystem. This tutorial will guide you through setting up an IAM user, configuring the AWS CLI, installing and configuring S3FS, and finally mounting the S3 bucket on your EC2 instance.

Task 1: Setting Up an IAM User

Step 1: Log in to AWS Management Console

Go to the AWS Management Console and sign in to your AWS account.

Step 2: Navigate to IAM Service

In the AWS Management Console, type "IAM" in the search bar or find it under the "Security, Identity, & Compliance" section.

Step 3: Create a New IAM User

  1. Click on "Users" from the left-hand menu and then select "Add user."

  2. Enter a username for the new IAM user.

Step 4: Set Permissions

Assign a policy for S3 access by either creating a new policy or using an existing one that provides the necessary S3 access permissions.

Step 5: Review and Create User

  1. Review the user details and create the user.

  2. Ensure to securely save the provided access key and secret access key.

Task 2: Setting Up AWS CLI on EC2 Instance

Step 1: Log in to EC2 Instance

Connect to your EC2 Linux instance using SSH:

ssh -i your-key.pem ec2-user@your-instance-ip

Step 2: Install AWS CLI

Update the package list and install AWS CLI by running the following commands:

sudo apt update
sudo apt install awscli -y

Step 3: Configure AWS CLI

Configure AWS CLI by running the aws configure command and providing the access key, secret key, default region, and preferred output format:

aws configure

Step 4: Test AWS Configuration

Verify the AWS configuration by running aws s3 ls to list your S3 buckets. If configured correctly, it should display a list of buckets.

aws s3 ls

Task 3: Mounting the S3 Bucket Using S3FS

Step 1: Install S3FS

Install S3FS by updating the package list and installing S3FS using the following commands:

sudo apt-get update
sudo apt-get install s3fs -y

Step 2: Create Mount Directory

Create a directory for mounting the S3 bucket. For example, create a directory named "bucket" in your home directory:

mkdir /home/ubuntu/bucket

Step 3: Add Files to Directory

Add some files to the "bucket" directory. You can create empty files using the touch command:

cd /home/ubuntu/bucket
touch day89.txt test.txt hello.txt

Step 4: Mount S3 Bucket

Mount your S3 bucket using S3FS. Replace <your-bucket-name> with the actual name of your S3 bucket:

aws s3 sync /home/ubuntu/bucket s3://<your-bucket-name>

Accessing S3 Data

Your S3 bucket is now successfully mounted in the "bucket" directory. Navigate to the directory and access the contents of the S3 bucket as if they are local files on your EC2 instance:

cd /home/ubuntu/bucket


By following these steps, you have successfully created an IAM user, configured AWS CLI, installed and configured S3FS, and mounted an S3 bucket on your Amazon EC2 instance. This setup allows you to seamlessly work with your S3 data directly from your EC2 instance, simplifying data management and enhancing your workflow.

Happy Learning!

Follow me on LinkedIn.