Attaching and mounting an S3 volume to an EC2 Linux instance

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

Related Posts

Secure supply chain: SBOM, SLSA, signing, provenance (plain English)

If you ship software today, you don’t just ship your code. You ship: That whole chain is your software supply chain. And attackers love it, because instead…

Read More

CI/CD for Cloud Apps: Build → Scan → Deploy → Rollback (a practical reference pipeline)

CI/CD sounds simple until you’re responsible for a production system and realize: This guide gives you a reference CI/CD pipeline you can adopt for most cloud apps…

Read More

Policy as Code: OPA/Rego basics + how it prevents bad infra

You know that feeling when an incident starts with a sentence like: Most “bad infra” isn’t malicious. It’s normal engineering drift:new hires, rushed PRs, copy-paste manifests, unclear…

Read More

Reusable IaC Module Design: naming, inputs/outputs, versioning (the engineer’s playbook)

Reusable IaC modules are like internal libraries: if the “API” is clean, teams move fast. If it’s messy, everyone forks it, patches it, and you end up…

Read More

GitOps explained: Argo CD vs Flux, patterns, and anti-patterns

GitOps is one of those ideas that sounds like buzzwords… until you run it for 30 days and suddenly you can’t imagine operating Kubernetes without it. Because…

Read More

Terraform vs CloudFormation vs Pulumi: which fits which team (the practical, engineer-first guide)

You’re not really choosing a tool. You’re choosing how your team will think about infrastructure for the next 2–5 years: This guide helps you decide fast, without…

Read More
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x