javatodev.com
Open in
urlscan Pro
63.250.43.6
Public Scan
URL:
https://javatodev.com/deploy-spring-boot-application-on-aws-elastic-beanstalk/
Submission: On January 21 via manual from US — Scanned from NZ
Submission: On January 21 via manual from US — Scanned from NZ
Form analysis
3 forms found in the DOMGET https://javatodev.com/
<form class="searchField-form" method="get" action="https://javatodev.com/">
<input type="text" name="s" class="searchField-form-input" placeholder="Search..." value="">
<button type="submit" class="searchField-form-btn btn"><span class="mnmd-icon" aria-hidden="true"><svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
<title></title>
<g id="search">
<path d="M29.71,28.29l-6.5-6.5-.07,0a12,12,0,1,0-1.39,1.39s0,.05,0,.07l6.5,6.5a1,1,0,0,0,1.42,0A1,1,0,0,0,29.71,28.29ZM14,24A10,10,0,1,1,24,14,10,10,0,0,1,14,24Z"></path>
</g>
</svg></span></button>
</form>
POST https://javatodev.com/wp-comments-post.php
<form action="https://javatodev.com/wp-comments-post.php" method="post" id="commentform" class="comment-form" novalidate="">
<p class="comment-notes"><span id="email-notes">Your email address will not be published.</span> <span class="required-field-message">Required fields are marked <span class="required">*</span></span></p>
<p class="comment-form-comment"><label for="comment">Comment <span class="required">*</span></label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required=""></textarea></p>
<p class="comment-form-author"><label for="author">Name <span class="required">*</span></label> <input id="author" name="author" type="text" value="" size="30" maxlength="245" autocomplete="name" required=""></p>
<p class="comment-form-email"><label for="email">Email <span class="required">*</span></label> <input id="email" name="email" type="email" value="" size="30" maxlength="100" aria-describedby="email-notes" autocomplete="email" required=""></p>
<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"> <label for="wp-comment-cookies-consent">Save my name, email, and website in this browser for the next time
I comment.</label></p>
<div class="sgr-main">
<div style="width: 304px; height: 78px;">
<div><iframe title="reCAPTCHA"
src="https://www.recaptcha.net/recaptcha/api2/anchor?ar=1&k=6LeuyqUjAAAAALq0TSA9JQAyhrvGbVzjhbzAvedr&co=aHR0cHM6Ly9qYXZhdG9kZXYuY29tOjQ0Mw..&hl=en&v=Gg72x2_SHmxi8X0BLo33HMpr&size=normal&cb=ue4r63zd84ye" width="304"
height="78" role="presentation" name="a-1dva5r1y1k2b" frameborder="0" scrolling="no" sandbox="allow-forms allow-popups allow-same-origin allow-scripts allow-top-navigation allow-modals allow-popups-to-escape-sandbox"></iframe></div>
<textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 40px; border: 1px solid rgb(193, 193, 193); margin: 10px 25px; padding: 0px; resize: none; display: none;"></textarea>
</div><iframe style="display: none;"></iframe>
</div>
<p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Post Comment"> <input type="hidden" name="comment_post_ID" value="1030" id="comment_post_ID">
<input type="hidden" name="comment_parent" id="comment_parent" value="0">
</p>
</form>
POST
<form id="mc4wp-form-1" class="mc4wp-form mc4wp-form-1646" method="post" data-id="1646" data-name="Javatodev-Form">
<div class="mc4wp-form-fields">
<p>
<label>Name: <input type="email" name="FNAME" placeholder="Your name" required="">
</label>
<label>Email address: <input type="email" name="EMAIL" placeholder="Your email address" required="">
</label>
</p>
<p>
<input type="submit" value="Sign up">
</p>
</div><label style="display: none !important;">Leave this field empty if you're human: <input type="text" name="_mc4wp_honeypot" value="" tabindex="-1" autocomplete="off"></label><input type="hidden" name="_mc4wp_timestamp"
value="1674300534"><input type="hidden" name="_mc4wp_form_id" value="1646"><input type="hidden" name="_mc4wp_form_element_id" value="mc4wp-form-1">
<div class="mc4wp-response"></div>
</form>
Text Content
menu JAVATODEV TUTORIALS IN BACKEND DEVELOPMENT TECHNOLOGIES * Spring Boot * Microservices * DevOps * Full-Stack * AWS * Start From Here * About Me * Developer Tools * Fake Rest API * JSON To Java Converter * JSON to Kotlin Converter * JSON to Groovy Converter * UUID Generator JAVATODEV TUTORIALS IN BACKEND DEVELOPMENT TECHNOLOGIES * AWS * DevOps * Spring Boot DEPLOY SPRING BOOT APPLICATION ON AWS ELASTIC BEANSTALK by Chinthaka Dinadasa posted on January 13, 2023 0 AWS Elastic Beanstalk is a fully managed service that makes it easy to deploy, run, and scale web applications and services in the AWS Cloud. When deploying Spring Boot applications, AWS Elastic Beanstalk is an excellent choice as it provides a simple and cost-effective way to run and scale Java web applications without worrying about the underlying infrastructure. The Elastic Beanstalk service is fully integrated with the Spring Boot framework, which allows you to deploy Spring Boot applications with minimal configuration easily. SPRING BOOT APPLICATION WE ARE GOING TO DEPLOY Here, I’ve developed minimal REST API with Spring Boot, Java 17, JPA, and H2 In-memory database. You can clone it from this repository. This API has a single endpoint where it reads the countries list from the H2 database and is exposed with the following URL. or else feel free to use any spring boot application to that you have access. DEPLOYMENT FLOW Let’s start the deployment of our Spring Boot application on AWS elastic beanstalk and expose that through public URL. USING ELASTIC BEANSTALK CLI In this tutorial, I’m going to use Elastic Beanstalk CLI which allows us to simply access the elastic beanstalk product on AWS and create any kind of environment we like. Also there is another way we can use AWS dashboard to achieve the same target. You can refer this official document in order to setup EB CLI on your development machine. SETTING UP APPLICATION ON ELASTIC BEANSTALK First we should create a new application and deployment environment on elastic beanstalk. We can achieve that with executing following command on project root. $ eb init then choose preferred AWS region and application name to create the deployment environment. Here I’ve used us-west-2 : US West (Oregon) for demonstration purposes. Initializing Elastic Beanstalk Environment to Deploy Spring Boot Application After completing this step you should asked to choose the platform, Here it should be Java and choose the java version which matches with your application, For me it is Java – Corretto 17 running on 64bit Amazon Linux 2. Selecting platform and deployment version Finally there will be asked to setup CodeCommit and setup SSH access to the EC2 instances that this setup will creates. But for the moment I’m not going to setup those. Code commit and SSH access setup elastic beanstalk So now we should have elastic beanstalk config.yml created on project root with config as below. Project structure after creating EB configuration branch-defaults: main: environment: null global: application_name: spring-boot-elastic-beanstalk branch: null default_ec2_keyname: null default_platform: Corretto 17 running on 64bit Amazon Linux 2 default_region: us-west-2 include_git_submodules: true instance_profile: null platform_name: null platform_version: null profile: null repository: null sc: git workspace_type: Application CONFIGURE JAR FILE FOR ELASTIC BEANSTALK DEPLOYMENT By default, EB CLI use git history and create zip file to with latest application code when deploying. But that will not work with spring boot application since it should be deploy using JAR file build on application build folders. We need to show that specific JAR build in order to deploy on elastic beanstalk. We can achieve that with adding following into the .elasticbeanstalk/config.yml. Here I’m using Gradle for application build, it creates the application JAR build on /build/libs/ folder on project root. deploy: artifact: build/libs/spring-boot-elastic-beanstalk-0.0.1-SNAPSHOT.jar SETTING UP DEPLOYOMENT ENVIRONMENT AND PROCESS INITIAL DEPLOYMENT Now, we can deploy our JAR build on EB environment, with following command, $ eb create choose environment name, DNS name prefix which will used to expose our API with domain name and load balancer type. Here I’ve used application load balancer and skipped creating spot instance fleet. Elastic Beanstalk Environment Creation Here you should see EB CLI started to deploy your JAR built on AWS, and it should be started to upload with above command. Output on Deploying Spring Boot Application on Elastic Beanstalk SETTING APPLICATION PORTS TO EXPOSE WITH PUBLIC URL Since we are using default port with spring boot application, It runs on port 8080. But elastic beanstalk uses nginx internally and it routes public domain entry into port 5000. Hence we have to setup our application to run with port 5000 with following command. $ eb setenv SERVER_PORT=5000 Now our deployment should be done, and we could access our API through the public URL published on the elastic beanstalk dashboard. Environments on Elastic Beanstalk Dashboard Access the API using public URL and /api/v1/countries and it should return following JSON reponse. BENEFITS OF USING ELASTIC BEANSTALK One of the key benefits of using AWS Elastic Beanstalk for Spring Boot applications is that it abstracts away the underlying infrastructure so you don’t have to worry about provisioning and managing servers. EC2 Instances created automatically on Elastic Beanstalk Environment Setup. The service automatically provisions and scales the infrastructure to match the number of requests and the amount of traffic your application receives, taking care of all the underlying infrastructure for you. This allows you to focus on developing and deploying your application without worrying about the operational aspect of running it. Additionally, with the simple and cost-effective pricing model, it’s a great option for deploying and running Spring Boot applications on the cloud. Auto Scaling Groups created automatically Load balancers provisioned on environment creation automatically CONCLUSIONS In this article we have discussed how we can deploy a spring boot application on AWS elastic beanstalk on a practical scenario. The implementation of all these examples and code snippets can be found in our Github repository. Happy coding. RECOMMENDED READING 1. How to Setup HashiCorp Vault With Spring Boot Application 2. Task Scheduling on Spring Boot Using @Scheduler 3. How to Use Amazon SQS With Spring Boot 4. Multiple Datasources With Spring Boot Data JPA 5. How To Handle Multiple Message Properties In Spring Boot 6. Spring Boot JWT Authentication using Spring Security AWSSpring Boot CHINTHAKA DINADASA Tech Lead with AWS SAA Who is specialised in Java, Spring Boot, and AWS with 8+ years of experience in the software industry. Website: https://javatodev.com Posts created: 38 Previous article How to Setup HashiCorp Vault With Spring Boot Application No newer article There are no comments yet No comments LEAVE A REPLY CANCEL REPLY Your email address will not be published. Required fields are marked * Comment * Name * Email * Save my name, email, and website in this browser for the next time I comment. NEWSLETTER Name: Email address: Leave this field empty if you're human: RECENT POSTS * BUILDING MICROSERVICES WITH SPRING BOOT – FREE COURSE WITH PRACTICAL PROJECT May 6, 2021 * SPRING BOOT PAGINATION, SORTING AND FILTERING December 19, 2020 * DOCKER COMPOSE FOR SPRING BOOT WITH MYSQL January 8, 2021 * HOW TO USE AMAZON SQS WITH SPRING BOOT November 29, 2022 * MICROSERVICES – SERVICE REGISTRATION AND DISCOVERY WITH SPRING CLOUD NETFLIX EUREKA May 10, 2021 * Resources * Contact Us * DMCA (Digital Millennium Copyright Act Policy) * Cookie Privacy Policy * Terms and Conditions JAVATODEV From Sri Lanka <3 Back to toplnr-arrow-up Close * Spring Boot * Microservices * DevOps * Full-Stack * AWS * Start From Here * About Me * Developer Tools * Fake Rest API * JSON To Java Converter * JSON to Kotlin Converter * JSON to Groovy Converter * UUID Generator