Rodion Burden
Rodion Burden

Reputation: 31

How to access s3 bucket from ec2 instance

I am trying to access my s3 bucket via the ec2 instance. I follow the AWS online tutorial.

(Mac) I have set up an ec2 instance. Created a bucket and synced some files from local to the bucket. Created an IAM role for the ec2 instance with fullS3access. Then ssh to the ec2 instance. When I list my s3 bucket, I can see the bucket I want to access. But I cannot access the bucket with cd. The tutorial uses the line 'cd s3-demo' when in the instance, but I dont understand where he got this name from, what it stands for and what it would be in my case.

[Mac]$ aws s3 sync 'folder_name' s3://'bucket_name'/'folder_name'
[Mac]$ ssh -i /Users/../''.pem ec2-user@'public_DNS'
[ec2-user@'public_DNS' ~]$ aws s3 ls
 [out]: 'name of the bucket I created'
[ec2-user@'public_DNS' ~]$ cd 'name of the bucket'
 [out]: -bash: cd: 'name of the bucket': No such file or directory

Online course: AWS Cloud Practitioner Essentials (Second Edition)

Upvotes: 1

Views: 4268

Answers (2)

John Rotenstein
John Rotenstein

Reputation: 269330

Amazon S3 is an object storage system. It is intended to be accessed via API calls.

While there are some utilities that emulate mounting S3 as a drive, you will likely run into difficulties using such an interface for production purposes. (Behind the scenes, it is making API calls to S3, just like you would.)

Instead, I would recommend either using the AWS Command-Line Interface (CLI), which is simply a Python program that is making the API calls for you, or using an AWS SDK for your preferred programming language to communicate with Amazon S3.

Upvotes: 1

James Dean
James Dean

Reputation: 4421

This is not the way S3 works, You need to make API call for every request(PUT, GET etc) using awscli command. Here are some document to start with: https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html

To access it your way, you need to mount the bucket in your system and then you can access it like a system directory. To do this, you can use s3fs: https://github.com/s3fs-fuse/s3fs-fuse

Upvotes: 0

Related Questions