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'.

질문됨 일 년 전3245회 조회
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
답변함 일 년 전
  • 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
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠