Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy file from Elastic beanstalk to local machine

I have connected to Elastic Beanstalk using:

eb ssh XXXXXX --profile=xx

Now I want to copy a file to my local machine, how do I do that?

like image 616
iKode Avatar asked Oct 28 '16 15:10

iKode


3 Answers

To figure out what IP address and keyfile to use with scp, you can run eb ssh my-env-name and pay attention to the first few lines of output:

  INFO: SSH port 22 open.
  INFO: Running ssh -i /Users/MyHome/.ssh/eb.pem ec2-user@<eb-env-ip-address>

Then, we can use these details for the actual scp command (replacing ssh with scp and adding file paths):

  scp -i /Users/MyHome/.ssh/eb.pem ec2-user@<eb-env-ip-address>:/path/to/file .
like image 63
pscl Avatar answered Oct 17 '22 21:10

pscl


You can use regular scp command.

scp -i ~/.ssh/beanstalk-env-key.pem [email protected]:/path/to/file.txt ./file.txt
like image 29
ALex_hha Avatar answered Oct 17 '22 22:10

ALex_hha


I think pscl's answer is the best one. Its very easy and is only 2 steps.

But, if you wanted to script it and maybe have only a single step, you could build on Michal's answer here.

scp -i ~/.ssh/yourkey.pem ~/localfile ec2-user@`aws ec2 describe-instances --filters "Name=tag:elasticbeanstalk:environment-name,Values=ENVIRONMENT_NAME" --query 'Reservations[].Instances[].PublicIpAddress' --output text`:~/

You could write an alias pretty easily. The next step would be working out how to dynamically swap in the environment name based on current branch.

like image 3
Christian Avatar answered Oct 17 '22 21:10

Christian