Reputation:
I need to download a file from S3 bucket from my EC2 instance. Both my S3 and EC2 are in the same VPC. I cannot make the S3 bucket public. Can someone help me on how to achieve this ?
Upvotes: 0
Views: 3635
Reputation: 270104
The easiest way to copy a file from S3 is to use the AWS Command-Line Interface (CLI). It has a aws s3 cp
command that can download or upload a file.
If an IAM Role has been assigned to the Amazon EC2 instance, then the AWS CLI will automatically use the permissions assigned to the IAM Role. Therefore, make sure that the IAM Role has the necessary permissions to access the S3 bucket. There is no need to make the bucket public, and no need to put a Bucket Policy on the bucket.
Please note that Amazon S3 does not live in a VPC. The endpoint for S3 is on the Internet. You can, however, create a VPC Endpoint in the VPC that can connect to S3 directly if desired.
Upvotes: 2
Reputation: 429
Use below approach, 1)Bucket policy and ec2 instance role will allow you to download things from a bucket. Look them 2 items up.
2)Use AWS CLI, login to S3 bucket using IAM role. Command to login to that bucket is AWS configure. It will then prompt for Access key and Secret access key for s3 bucket. You should then be able to use AWS S3 CP command to copy files.
Upvotes: 0