Day 89 - Project 10
3 min read
![Cover Image for Day 89 - Project 10](https://cdn.hashnode.com/res/hashnode/image/upload/v1706439123181/a4edab70-77c5-4c11-9c2a-1332657c0c21.png?w=1600&h=840&fit=crop&crop=entropy&auto=compress,format&format=webp)
Task-01
Create an IAM user and set policies for the project resources using this blog.
Utilize and make the best use of aws-cli
Mounting an AWS S3 bucket on an Amazon EC2 Linux instance using S3FS is a common task for storing and accessing data in an S3 bucket as if it were a local file system. S3FS is a FUSE-based file system that allows you to mount an S3 bucket to an EC2 instance. Here are the steps to accomplish this:
1. Set Up an Amazon EC2 Instance:
If you don't already have an Amazon EC2 instance, you'll need to set one up. Ensure that the instance has the necessary permissions to access S3 by using an IAM role with S3 permissions.
2. Connect to the EC2 Instance:
Use SSH or your preferred method to connect to your EC2 instance.
3. Install S3FS:
You need to install S3FS on your EC2 instance. You can do this using package managers like yum
or apt-get
depending on your Linux distribution. Here are commands for common distributions:
For Amazon Linux:
sudo yum update -y
sudo yum install s3fs-fuse -y
For Ubuntu/Debian:
sudo apt-get update
sudo apt-get install s3fs
4. Configure S3FS:
Once installed, you need to configure S3FS with your AWS credentials and the bucket you want to mount. You can do this by creating a credentials file and an S3FS configuration file.
Create an AWS credentials file (e.g., ~/.aws/credentials
) with your AWS access and secret keys:
mkdir ~/.aws
touch ~/.aws/credentials
chmod 600 ~/.aws/credentials
Edit the ~/.aws/credentials
file and add your AWS access and secret keys:
[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_SECRET_KEY
Create an S3FS configuration file (e.g., ~/.s3fs_config
) and set the IAM role or the credentials file path:
touch ~/.s3fs_config
chmod 600 ~/.s3fs_config
Edit the ~/.s3fs_config
file and add the configuration:
# Use IAM role (if applicable)
use_cache = false
# Use credentials file (if not using IAM role)
url = https://s3.amazonaws.com
use_cache = false
5. Mount the S3 Bucket:
Now, you can mount the S3 bucket to a directory on your EC2 instance using the s3fs
command:
mkdir /path/to/mount/point
s3fs your-s3-bucket-name /path/to/mount/point -o passwd_file=~/.s3fs_config -o umask=022
Replace your-s3-bucket-name
with the name of your S3 bucket and /path/to/mount/point
with the directory where you want to mount the S3 bucket.
6. Access and Use the S3 Bucket:
You can now access the S3 bucket as if it were a local directory on your EC2 instance. Any files you write to the mount point will be stored in the S3 bucket.
Remember that S3FS has some limitations and may not be suitable for all use cases, especially high-performance scenarios. Make sure to review and test thoroughly for your specific requirements.