Tuesday, 21 May 2019

How to copy a file to or from Amazon S3 and your EC2 instance By Raj Gupta




Option 1:- By using GET or wget

 The wget utility is an HTTP and FTP client that allows you to download public objects from Amazon S3. It is installed by default in Amazon Linux and most other distributions, and available for download on Windows. To download an Amazon S3 object, use the following command, substituting the URL of the object to download.

[root@ip-172-31-33-189 ~]# wget https://s3.amazonaws.com/raj05212019/pic1.png

[root@ip-172-31-33-189 ~]# ls
pic1.png

So one file pic1.png downloaded from s3 bucket to our EC2 server.

This method requires that the object you request is public; if the object is not public, you receive an "ERROR 403: Forbidden" message. If you receive this error, open the Amazon S3 console and change the permissions of the object to public


Option 2:-  By using AWS Command Line

For this we required a system in which AWS CLI tool already install.

Use the following command to copy an object from Amazon S3 to your instance by using AWS CLI

[root@ip-172-31-33-189 ~]# aws s3 cp s3://raj05212019/pic1.png pic2.png
download: s3://raj05212019/pic1.png to ./pic2.png
[root@ip-172-31-33-189 ~]# ls
pic1.png  pic2.png

Use the following command to copy an object from your instance back into Amazon S3. 

[root@ip-172-31-33-189 ~]# aws s3 cp pic2.png s3://raj05212019/pic2.png
upload: ./pic2.png to s3://raj05212019/pic2.png

Use the following command to download an entire Amazon S3 bucket to a local directory on your EC2 server.

[root@ip-172-31-33-189 rahul]# aws s3 sync s3://raj05212019 /root/rahul
download: s3://raj05212019/ramu.txt to ./ramu.txt
download: s3://raj05212019/pic1.png to ./pic1.png
download: s3://raj05212019/pic2.png to ./pic2.png
[root@ip-172-31-33-189 rahul]# ls
pic1.png  pic2.png  ramu.txt

The aws s3 sync command can synchronize an entire Amazon S3 bucket to a local directory location. This can be helpful for downloading a data set and keeping the local copy up-to-date with the remote set. If you have the proper permissions on the Amazon S3 bucket, 

you can push your local directory back up to the cloud when you are finished by reversing the source and destination locations in the command.

[root@ip-172-31-33-189 rahul]# aws s3 sync /root/rahul s3://raj05212019 



1 comment:

  1. Your IP address is going to be displayed as a collection of numbers.Want to know more about dlink router login? check out this site.

    ReplyDelete