Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move files from amazon ec2 to s3 bucket using command line

In my amazon EC2 instance, I have a folder named uploads. In this folder I have 1000 images. Now I want to copy all images to my new S3 bucket. How can I do this?

like image 733
Pacts Ramun Avatar asked Feb 08 '15 15:02

Pacts Ramun


People also ask

Can we copy folder from EC2 to S3?

After generating the Access key ID and secret access key, log into the EC2 instance using SSH and configure the access key. It will ask for an access key ID and the secret access key. Provide the credentials we just generated. Now the EC2 instance has access to upload the files on S3 using the command line interface.

How do I transfer local files to AWS S3?

You have two options for uploading files: AWS Management Console: Use drag-and-drop to upload files and folders to a bucket. AWS CLI: With the version of the tool installed on your local machine, use the command line to upload files and folders to the bucket.


1 Answers

First Option sm3cmd

Use s3cmd

s3cmd get s3://AWS_S3_Bucket/dir/file 

Take a look at this s3cmd documentation

if you are on linux, run this on the command line:

sudo apt-get install s3cmd 

or Centos, Fedore.

yum install s3cmd 

Example of usage:

s3cmd put my.file s3://pactsRamun/folderExample/fileExample 

Second Option

Using Cli from amazon

Update

Like @tedder42 said in the comments, instead of using cp, use sync.

Take a look at the following syntax:

aws s3 sync <source> <target> [--options] 

Example:

aws s3 sync . s3://my-bucket/MyFolder 

More information and examples available at Managing Objects Using High-Level s3 Commands with the AWS Command Line Interface

like image 117
Ethaan Avatar answered Sep 23 '22 17:09

Ethaan