Attaching and mounting an S3 volume to an EC2 Linux instance

Posted by

Attaching and mounting an S3 volume to an EC2 Linux instance involves creating an S3 bucket, installing necessary tools, and using s3fs to mount the S3 bucket as a filesystem. Here’s a step-by-step guide:

Step 1: Create an S3 Bucket

  1. Log in to your AWS Management Console.
  2. Navigate to the S3 service.
  3. Click on “Create bucket.”
  4. Provide a unique bucket name and select the region.
  5. Configure bucket settings as needed and create the bucket.

Step 2: Launch an EC2 Instance

  1. Log in to your AWS Management Console.
  2. Navigate to the EC2 service.
  3. Launch an instance with your preferred configuration.
  4. Make sure to attach a role to your instance with S3 access permissions (e.g., AmazonS3FullAccess policy).

Step 3: Connect to Your EC2 Instance

  1. Use SSH to connect to your EC2 instance.
ssh -i /path/to/your-key-pair.pem ec2-user@your-ec2-instance-public-dns

Step 4: Install s3fs

  1. Update your package repository and install dependencies.
sudo apt-get update -y
sudo apt-get install -y s3fs

If you are using a RedHat-based system (like Amazon Linux or CentOS):

sudo yum update -y
sudo yum install -y s3fs-fuse

Step 5: Configure s3fs

  1. Create an S3 credentials file.
echo "ACCESS_KEY_ID:SECRET_ACCESS_KEY" > ~/.passwd-s3fs
chmod 600 ~/.passwd-s3fs
  1. Replace ACCESS_KEY_ID and SECRET_ACCESS_KEY with your AWS access key and secret key.

Step 6: Mount the S3 Bucket

  1. Create a directory where you want to mount the S3 bucket.
mkdir ~/s3bucket

Mount the S3 bucket using s3fs.

s3fs your-bucket-name ~/s3bucket -o passwd_file=~/.passwd-s3fs

Step 7: Verify the Mount

  1. List the contents of the mounted directory to verify
ls ~/s3bucket

Step 8: Automate Mounting (Optional)

To automate the mounting process so that it persists across reboots, add the following entry to your /etc/fstab file:

  1. Open /etc/fstab in a text editor.
sudo nano /etc/fstab

Add the following line to the file:

s3fs#your-bucket-name /home/ec2-user/s3bucket fuse _netdev,passwd_file=/home/ec2-user/.passwd-s3fs 0 0

Adjust the paths as needed for your setup.

Save and close the file.

Test the configuration by unmounting and remounting the directory:

sudo umount ~/s3bucket
sudo mount ~/s3bucket
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x