26

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?

Positonic
  • 9,151
  • 14
  • 57
  • 84

3 Answers3

38

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 .
Jon Burgess
  • 2,035
  • 2
  • 17
  • 27
pscl
  • 3,322
  • 25
  • 29
13

You can use regular scp command.

scp -i ~/.ssh/beanstalk-env-key.pem ec2-user@beanstalk.host.ip:/path/to/file.txt ./file.txt
ALex_hha
  • 1,345
  • 15
  • 16
  • 3
    Keep in mind that you will have to open port 22 in your elastic beanstalk security group, if it is not already open. The `eb ssh` command does this automatically for you, but running `scp` from the command line will not. – Jeff Kilbride Dec 22 '17 at 20:37
  • 1
    An easy way to do that might just be to `eb ssh` into the machine with a second console. – tgf Sep 19 '18 at 17:40
  • 1
    Use `-r` switch to copy sub-folders recursively. `scp -r -i ~/.ssh/beanstalk-env-key.pem ec2-user@beanstalk.host.ip:/path/to/file.txt ./file.txt` – Tirtha R Oct 31 '18 at 15:06
3

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.

Christian
  • 3,917
  • 2
  • 23
  • 40
  • pscl's answer does not tell us how to get the actual file. It merely tells us how to figure out what IP address and keyfile to use. – Aditya Satyavada May 22 '18 at 05:08
  • Yes my answer is to be used in conjunction with the `scp` command in Alex_hha's answer below. But Christian's answer is clever if you need to do it on a regular basis. – pscl Aug 30 '18 at 18:39
  • I edited @pscl's answer to include the `scp` part. Maybe the edit will be accepted. – Jon Burgess Aug 21 '19 at 06:28
  • Best to add a fresh answer rather than change other people's answers. – Christian Aug 21 '19 at 06:32