Is there a way to transfer a file from one EC2 instance to another EC2 instance using AWS cli on the first EC2 instance?

0

I know that its possible to upload/download a file from EC2 to/from s3 using the cp command. But is it also possible to use the AWS cli to transfer a file from an EC2 instance to another EC2 instance? The EC2 instance that does the uploading has an IAM role attached with permission 'EC2FullAccess'.

已提问 1 年前3256 查看次数
2 回答
1

Hi there,

Here are the steps you can try:

Login to the first EC2 instance using SSH.

Use the scp command to transfer the file to the second EC2 instance. The command should be in the following format: ruby

scp /path/to/local/file ec2-user@<second-ec2-instance-public-ip>:/path/on/remote/server

Replace /path/to/local/file with the path of the file you want to transfer from the first EC2 instance. Replace <second-ec2-instance-public-ip> with the public IP address of the second EC2 instance. Replace /path/on/remote/server with the path of the directory where you want to store the file on the second EC2 instance.

Enter the password for the ec2-user account on the second EC2 instance when prompted.

Once the file transfer is complete, you should be able to access the file on the second EC2 instance

Let us know if it works.

Tiago
已回答 1 年前
  • Is there any way to do this without entering a password? For instance by using a IAM role that has EC2FullAccess permission?

  • scp is not aware of IAM policies. But you can surely use SSH key pairs for passwordless login / file transfer using scp.

0

It's not possible to use the AWS CLI commands for this.

As you've already identified, you can use aws s3 cp .... and treat an S3 bucket as an intermediate object store to achieve this. But there isn't an equivalent aws ec2 cp [source] [target] command, which sounds like what your question is about (see aws ec2 help for the full options).

Tiago's answer here, of using the Linux scp command, is your best option, assuming that port 22 is open between source and target.

profile picture
专家
Steve_M
已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则