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

posta un anno fa3256 visualizzazioni
2 Risposte
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
con risposta un anno fa
  • 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
ESPERTO
Steve_M
con risposta un anno fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande