Hot questions for Using Ubuntu in amazon ec2

Top Java Programmings / Ubuntu / 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]


I am having trouble getting envrionment variables on my Ubuntu insance on EC2.

Here is what is in my /etc/environment file:


now when I load up a Scala interpreter I try and do the following:

^Cubuntu@ip-172-31-35-31:~/suredbits-web$ sudo sbt console
[info] Loading project definition from /home/ubuntu/suredbits-web/project
[info] Set current project to suredbits-web (in build file:/home/ubuntu/suredbits-web/)
[info] Downloading Bower dependencies for suredbits-web
[info] 1.0.272 against
[info] git://
[info] 0.10.2 against git://^0.10.0
[info] git://
[info] 0.10.4 against git://^0.10.4
[info] git://
[info] 0.10.4 against git://
[info] git://
[info] 0.10.1 against git://
[info] Starting scala interpreter...
Welcome to Scala version 2.11.4 (OpenJDK 64-Bit Server VM, Java 1.7.0_79).
Type in expressions to have them evaluated.
Type :help for more information.

scala> System.getenv("PATH");
res0: String = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

scala> System.getenv("DATABASE_URL");
res1: String = null


I have 'rebooted' my EC2 instance hoping that that would help pick up the new environment variable. I also have tried adding the environment variable to my ~/.bashrc which didn't work.


I see that the issue is running it with sudo command. It causes the overriding of your environmental variables. To save your environmental variables, run it with the -E flag, i.e.

sudo -E sbt console


I followed following steps to run my web application

  1. I have created an ec2 instance of ubuntu 16.04 LTS on aws.
  2. Using remote login by ssh, I installed java 8, and then tomcat: sudo apt-get install tomcat7. (tomcat9 could not install using same command)
  3. I renamed my war file to ROOT(because project name should not be in URL) and copied it to webapps folder.
  4. After starting tomcat, using http://IP_address:8080 I can access my website. default setting in server.xml: connector port="8080" ... I checked which services are running netstat –plnt 8005(server shutdown port), 8080(connector port)
  5. I changes port number from server.xml to 80: connector port="80" .. Then started tomcat. I could not access my website. also following command doesn't show any service running on port 80. netstat –plnt 8005(server shutdown port)

What changes need to be made so that website will be accessible without entering any port number in URL. (I already mapped domain name to IP address.) I want to use java 8 features hence I prefer tomcat 9 installation.


A simple solution (tested on EC2 running on ubuntu). Basically redirects all traffic from port 80 to 8080.

sudo /sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

People also suggest installing iptables-persistent (through apt-get install) to save the changes, but I personally haven't tested it out.

Make sure you allow port 80 in your AWS console. To do that, under Network & Security go to Security groups, choose the group of your EC2 instance, select it and go to Inbound (at the bottom), then edit, and Add Rule with port 80. You might have to wait for some time.