Install and Config Mountpoint for Amazon S3 to access to your S3 bucket via SFTP
Using AWS Transfer Family for SFTP can cost over $200/month. Instead, you can set up a more cost-effective SFTP solution by hosting an SFTP server on an EC2 instance and mounting an S3 bucket using Mountpoint for S3. Below are the steps to achieve this:
A. Mounting an S3 Bucket to an EC2 Instance
Step 1: Create an EC2 Instance
- Launch an EC2 instance using a supported Amazon Linux or Ubuntu AMI.
Step 2: Create an IAM Role for S3 Access
- Navigate to IAM > Roles > Create Role.
- Trusted Entity Type: AWS Service
- Use Case: EC2
- Attach a suitable policy:
- Select AmazonS3FullAccess (grants full access to S3) or
- Create a custom policy for bucket-specific access.
Step 3: Attach the IAM Role to the EC2 Instance
- In the EC2 console, select the instance.
- Click Actions > Security > Modify IAM Role and assign the role you created.
Step 4: Install Mountpoint for S3
For Amazon Linux:
sudo yum update -y && sudo yum upgrade -y //skip this line if you don't want to update
wget https://s3.amazonaws.com/mountpoint-s3-release/latest/x86_64/mount-s3.rpm
sudo yum install -y ./mount-s3.rpm
For Ubuntu:
sudo apt update && sudo apt upgrade -y //skip this line if you don't want to update
wget https://s3.amazonaws.com/mountpoint-s3-release/latest/x86_64/mount-s3.deb
sudo apt-get install -y ./mount-s3.deb
Note: for Graviton instances, replace x86_64
with arm64
in the URL
Verify Installation:
mount-s3 --version
Step 5: Mount the S3 Bucket
Create a directory for the mount point
mkdir ~/mnt/s3bucket
Mount the S3 bucket:
mount-s3 <bucketname> ~/mnt/s3bucket
To mount a specific prefix (subdirectory) within the bucket:
mount-s3 <bucketname> --prefix <bucket-subdirectory>/ ~/mnt/s3bucket
To enable delete permissions:
mount-s3 <bucketname> --add-delete --prefix <bucket-subdirectory>/ ~/mnt/s3bucket
Example:
mount-s3 mybucket --add-delete --prefix companyA/ ~/mnt/s3bucket/companyA
Verify mounting
ls ~/mnt/s3bucket
Unmount the bucket:
umount ~/mnt/s3bucket