berk geylani berk geylani - 2 months ago 12x
Bash Question

Is there anyway to deploy app from Travis to Amazon ec2?

I want to deploy my app to Amazon ec2(Ubuntu instance) when my tests will be succeed.

  1. 1-)I have git hub repository which also a project and travis.yml.

    2-)Travis can check my project and it succeed.

    3-)When it succeed,a shell command should deploy my app to amazon ec2.(Confused Step)

I have learnt these but i can't do anything to
I know in travis.yml file should be like :

I know some answers but i couldn't solve.These are solutions with my problems.



curl --ftp-create-dirs -T uploadfilename -u $FTP_USER:$FTP_PASSWORD


In this solution,I can't find my ftp_user and password,if i know them,is it possible to transfer data with using scp.

And the other solution is:(using pem file)


scp -i "[pemFileName].pem" [A File] [hostname]

The code written after "after_success" is working from terminal but the problem in here is i can't upload my pem file to Travis.And i don't want to push pem file to github.(For security)

Briefly problem: How can i deploy my app to Amazon EC2 when my test succeed on travis?


Travis has the ability to encrypt/decrypt files stored in your git repository. You can store an encrypted version of your private key needed to scp into your EC2 instance.


In my case I use a Bash script that, if the right conditions are satisfied, (1) decrypts the file according to Travis' instructions; and then (2) scp's the build over to the EC2 instance using the decrypted .pem key.

Note that your scp command should incorporate some way to deal with StrictHostKeyChecking. This will disable it entirely:

scp -i [path/to/id/file] -o StringHostKeyChecking=no [source] [destination]

Though a more secure route is to get the host key fingerprint (e.g., ssh-keyscan [host]) and use as part of the scp command:

scp -i [path/to/id/file] -o UserKnownHostsFile=path/to/custom/known_hosts [source] [destination]