How To DevOps with aws and java
In this new edge software development world, it is almost obvious that as a developer you will one day find yourself in a situation where you want to build , deploy , run and maintain your application all by yourself or maybe by yourself.
This is where DevOps come in, so what is devops?? According to Wikipedia DevOps is a set of practices that combines software development (Dev) and IT operations (Ops). It aims to shorten the systems development life cycle and provide continuous delivery with high software quality.[1][2] DevOps is complementary with Agile software development; several DevOps aspects came from Agile methodology.
Today I will take you through a simple process of how to get started as a devops Engineer. we will use the best tools and platforms available in the market today i.e aws ec2, java springboot, ubuntu OS.
DEVELOPMENT (DEV) This is the first aspect of devops where we are required to develop an application using our language of choice. for me I’ll choose a springboot application packaged as a jar file ready to run.
OPERATION (OPS) Let us deploy our app to cloud (aws ec2 instance) 1. Create a free account at aws (you have 12 months free usage so go ahead) 2. on the aws management console create an ec2 instance (elastic cloud compute) this is our virtual computer that runs in the cloud for us. 3. Choose an AMI (Amazon machine Image ) this is the OS that will run in our ec2 instance follow the wizard and finish the process (download and keep the .pem file) 4.By now we have an application running in our localhost and also a server setup and running aws. 5. since I am hosting a java application , we will need to install the nessesary resources needed to run a java web app, luckily springboot comes bundled with almost everything we would need so lets dive in right away. 6.Let us connect to our server (ec2 instance) , this will vary depending on the operating system your local computer is running , follow this aws guide 7.we are now connected to our ec2 instance and ready to run commands to the online machine.
Hosting The Java Application
springboot applications are bundled with all its dependencies including web server and by default it will be a tomcart server listening on port 8080.
//build a runnable jar file
mvn clean package</span>
After the jar file we will need to copy it to our ec2 instance file system. run this command from a terminal in your local computer. this will copy the file from your computer to the remote computer securely.(Ensure port 22 is open for ssh connections)
scp -i /path to your aws .pem file /path to your springboot jar file.jar [username@youre](mailto:ubuntu@ec2-18-191-245-196.us-east-2.compute.amazonaws.com)c2ip:~/</span>
Running Our application
install java on the server , run this commands on a terminal connected to your aws instance
sudo apt-get update
sudo apt-get install openjdk-8-jdk</span>
run your springboot applicaton. this command runs the application and opens it on port 8080, ensure your security groups is set to allow access of this application via the ports 80 and 8080,
java -jar app.jar</span>
Your app is running at yourec2ip:8080
Next Steps
Cheers for your deployment now read something about 1. Connecting an Rds db 2. configure a CI/CD pipeline (jenkins is a good option) 3.learn aboout ec2 security groups, user roles and other services
Happy coding…..
Austine Gwa Software Developer