Skip to content

  • Home
  • Core Java
    • Write Your Own Immutable Class In Java
    • Write Your Own Singleton Class In java
    • Java Concurrent Package
    • Java Stream Revisited
    • Print odd and even numbers using thread
    • SOLID principles
    • Comparable Vs Comparator
    • Sort HashMap/TreeMap based on value
    • Deep and Shallow Copy in Java with examples
    • Find the frequency of each character in a String
    • How to avoid duplicate Employee objects in HashSet ?
  • Spring
    • Loose Coupling & Dependency Injection
    • Bean Scope
    • Spring Bean Lifecycle
    • IoC Container Vs Application Context Vs Bean Factory
    • @Component Vs @Service @Repository Vs @Controller
    • How to read properties file in Spring
    • Spring AOP (Aspect Oriented Programming)
    • @Component Vs @Bean in Spring
    • Exception Handling in SpringBoot
    • XML configuration Vs Annotations configuration in Spring
    • Spring Data JPA
    • Spring Data REST
  • Spring Security
    • Spring Security with Form, Basic and JWT
    • Security Configuration in Spring Boot Apps
    • Security Protocols & Frameworks
    • Okta OAuth 2.0 SSO with Springboot
    • Spring Boot 2.x Security using Username Password
    • Spring Boot 2.x Security using JWT
    • Spring Boot 3.x Security using Username Password
    • Spring Boot 3.x Security using JWT
  • Microservices
    • Spring Cloud Config (Server & Client)
    • Spring Boot Microservices Tutorial (Part 1 of 2)
    • Spring Boot Microservices Tutorial (Part 2 of 2)
    • Circuit Breaker – Resilience4j
    • The Twelve-Factor App Principles
  • Event Driven Microservices
    • What is Event Driven Microservice ?
    • What is Saga Design Pattern ?
    • What is CQRS Design Pattern ?
  • Spring AI
    • ChatGPT API + SpringBoot Integration
  • Hibernate & JPA
    • JPA vs JDBC
    • CRUD Example Using Spring Boot JPA + H2 + Gradle
    • MongoDB Atlas With Spring Boot Example
    • Transaction Management
    • Relationships in JPA & Hibernate
    • Hibernate First & Second Level Cache
    • Spring Boot Flyway Postgres
  • DevOps
    • What is Devops ?
    • Docker
    • Kubernetes (K8S)
    • Jenkins
    • Infrastructure As Code
  • Functional Programming
    • Functional Programming Vs Structured Programming
    • Java 8 Programs For Interview
    • Predicate, Function, Consumer and Supplier in Java 8
    • Sort a List having Employee objects using Java 8
    • Find Employee from List using Java 8
  • AWS
    • AWS S3
    • AWS EC2
    • EC2 Solutions Architecting
    • How to create an EC2 instance ?
    • How to connect to AWS EC2 instance ?
    • Deploy application to AWS
    • AWS Lambda Java Tutorial
    • Spring Cloud Functions
    • How to Start/Stop AWS ECS automatically using Java Spring?
    • Container Solution in AWS
    • AWS SQS, SNS, MQ and Kinesis
    • Databases in AWS
    • AWS VPC: Peering, Endpoint, VPN, Gateways- Internet, NAT, DX
    • Machine Learning in AWS
    • Storage Solutions in AWS
    • AWS ASG (Auto Scaling Group)
  • AWS Certifications
    • SAA-C03
      • Design Cost-Optimized Architectures
    • AWS Certified Solution Architect-Associate
      • Question 1
  • Kafka
    • Apache Kafka
    • Kafka Producer & Consumer Example Using Spring boot & Conduktor
  • Angular
    • Angular Tutorial – Part 1
    • Angular Tutorial – Part 2
  • Miscellaneous
    • How to add a project to Git/GitHub/GitLab
    • How to Clone a project from Git/GitLab using Git Bash
    • How to query Oracle tables based on some date ?
    • How to highlight text in WordPress ?
    • How to add Page Jumps in WordPress page ?
  • Interview Preparation
    • Core java interview questions
    • Java Threads Interview Questions
  • Contact Me
  • Toggle search form

Deploy application to AWS

How to deploy a spring boot application (.jar) on EC2:

This is the way of using AWS as IaaS(Infrastructure-as-a-service).

Login to the ec2 instance from Putty. The universal username is: ec2-user

  1. First check whether java is installed on ec2 by executing: java -version.
  2. If its not installed, install it by executing sudo yum install java-1.8.0 command to install the open jdk.
  3. Then using WinSCP copy paste the .jar file to the root folder.
  4. Execute the command: java -jar <application-name>.jar

Thats it !… Your application is running.

If this would be the URL of your endpoint in local machine: http://localhost:8080/app1/api/test1
Then you have to replace the “localhost” with the machine name like below:
http://ec2-13-233-102-65.ap-south-1.compute.amazonaws.com:8080/app1/api/test1
http://13.233.102.65:8080/app1/api/test1

P.S:
1. Once you stop the ec2 instance, the application will also stop. Although java and .jar file will be there.
2. After you start the ec2 instance again you need to run the .jar again to run the application.
3. The IP address will be different now.
4. Using this way of deployment it doesn’t create a S3 bucket for keeping the .jar file.

How to deploy a Spring boot application (.jar) to EC2 by AWS Elastic Beanstalk ?

This is the way of using AWS as PaaS (Platform-as-a-service).

Elastic Beanstalk has the AWS Elastic Load Balancer in it as well.

Here you can use the same above .jar file that you used in the above example.

Search for Elastic Beanstalk.
Click “Create Application”.
Give a name.
Tags are not required.
Choose Java as Platform. (if you have to uploaded a .war file then you need to choose Tomcat as Platform)
Choose Java 8 running on Amazon Linux.
Choose Upload your code.
Choose the .jar file from local machine.
Hit “Create Application”.

In the background it will create an ec2 instance and s3 bucket for the same. S3 will hold the .jar file.
It will take some time to launch.

Once the application is up you will see the below screen:

Once you hit the URL:

Add the below param in the configuration -> software

SERVER_PORT 5000

As we know the default port of a springboot application runs in 8080, similarly, the springboot application runs in port 5000 in Elastic Beanstalk EC2 instance.

The same can also be added in application.properties file of the springboot application:

server.port=5000

Wait for the server to up.
Then hit again:

It seems now the application is up. You need to hit the right endpoint. Add /app2/api/test1 to the end of the URL.
http://app22-env.eba-g2mzf55d.ap-south-1.elasticbeanstalk.com/app2/api/test1

That’s it !!…

Copyright © 2025 .

Powered by PressBook Blog WordPress theme