Skip to content

ecom-street/AWS-S3-Bucket-Mount-On-Amazon-EC2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

AWS-S3-Bucket-Mount-On-Amazon-EC2

We will learn how to use S3 as a filesystem on EC2 Linux machine.

s1

We are a preferred AWS consultant and offers the best cloud AWS consulting service. Our AWS-certified expert consultants conduct a thorough review and evaluation of your existing IT infrastructure and service interaction model to provide top-notch solutions.


Let's start!

  1. Create an EC2 Linux (I have used Ubuntu in this demo) instance. Keep everything as default and add the below user data script to install awscli and s3fs utlity from advance section of wizard

1

  1. Create an IAM user for s3fs

2

  1. Give the user a unique name and enable programmatic access

3

Set permission --> create a new policy

4

Select the service as S3 and include below access levels 6

Give the policy a unique name and click Create policy 7

Once the policy is created, go back to the IAM tab and hit refresh so that newly created policy is included in the list , filter by policy name and hit the enable checkbox to add the policy to our IAM user. 8

Hit create user

9

Once the user is created, download the credentials. We are going to use it later. 10

  1. Login to your Ec2 Instance

11

12

Go to your home directory and run below commands to create a new directory and to generate some sample files 5 Next step is to create an S3 bucket.

  1. Go to S3 service and create a new bucket give it a unique name and leave reast of the settings as default. Block public access to this bucket should be enabled by default.

13

Hit create bucket.

  1. Once the bucket is created, go to the ssh session and configure our AWS credentails for authentication using the IAM account that we have created.

Use the command

14

and provide the credential details that we have downloaded before

15

  1. create the credential file for s3fs.

s3fs supports the standard AWS credentials file stored in ${HOME}/.aws/credentials. Alternatively, s3fs supports a custom passwd file. The default location for the s3fs password file can be created: using a .passwd-s3fs file in the users home directory (i.e. ${HOME}/.passwd-s3fs)

file should have the below content:

16

You can run the below command as well:

17

18

  1. Now you can run the command to mount S3 bucket as a filesystem.

19

20

  1. Once it is mounted successfully, you can verify by running the command

21

22

  1. Add the entry in fstab using the below command so that the changes become persistent after the server reboot as well:

23

  1. Now the moment of truth, go to your S3 bucket and hit refresh, you should see the files that were present in your file system

26

25

  1. Let's now verify whether it's getting synced properly after a object delete/addition

Go to your S3 bucket, and upload a new file

24

Go to your ssh session and do ls in the same directory

27

The file that you just uploaded in your S3 bucket appears in your FileSystem.

Same way you can test the delete file operation. And it works both ways i.e if you perform any file operation on your filesystem, it will sync to your S3 bucket as well.

Releases

No releases published

Packages

No packages published