Open In App

How To Transfer Data from S3 to EC2?

Last Updated : 28 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Pre-requisite:- S3 and EC2

This article intends to make the readers aware of the data transfer process from S3 to EC2. Before going into the process, let us understand the circumstances when we would need this data transfer. In general, transferring data from S3 to EC2 can be useful when you need to perform computations on large datasets that are stored in S3, or when you want to use the data in an application or script that is running on an EC2 instance.

There can be multiple other Scenarios:

  • Process the data using an application or script that is running on an EC2 instance.
  • To load the data into a database that is running on an EC2 instance.
  • To transfer the data to an EC2 instance for backup or disaster recovery purposes.
  • To transfer the data from S3 to EC2 as part of a larger data processing or analysis pipeline.

The above discussed are a few scenarios, in which we might need to transfer data from S3 to EC2.

Steps to Transfer the Data from S3 to EC2

Step 1: First, login into your AWS account and click on “Services” present on the left of the AWS Management Console, i.e. the primary screen. And from the drop-down menu of options, tap on “S3”. Refer to the screenshot attached.

aws console

 

Step 2: In a while, you will be redirected to the S3 dashboard. Here, click on the bucket that contains the data you want to transfer to EC2. (If no bucket is present, follow this article to create one).

Click the “Actions” button and select “Download” from the drop-down menu. Make sure to select the objects you want to download. Refer to the attached screenshot for a better understanding.

s3 bucket

 

Step 3: Now, navigate to the EC2 service in the AWS Management Console. The same way we did for S3.

Step 4: Select the instance you want to transfer the data to and click the “Connect” button. And connect to your EC2 instance using SSH. Once connected to your EC2 instance, use the following CLI commands to transfer data from S3 to EC2. The syntax is as follows. And refer to the attached screenshot for a better understanding of the console.

$ aws s3 cp s3://my-bucket/path/to/
file.txt /local/path/to/destination/
connect bucket

 

Replace “my-bucket” with the name of your S3 bucket, and /path/to/file.txt with the path to the file you want to copy in the bucket. Replace /local/path/to/destination/ with the local path on your EC2 instance where you want to save the file. Refer to the attached screenshot for a better understanding.

ssh connecting

 

Here’s the SSH window screenshot for reference,

ssh window

 

If you want to copy an entire folder and all its contents from S3 to your EC2 instance, you can use the –recursive option as follows:

$ aws s3 cp s3://my-bucket/path/to/folder/ 
/local/path/to/destination/ --recursive

That’s it! You have successfully transferred data from S3 to EC2 using the AWS Management Console. I hope this helps! 

Step 5: Once completed you can simply use the wget command to download the data from S3 to your EC2 instance. 

$ wget https://s3.amazonaws.com/
my-bucket/my-file.txt"
downloading data

 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads