Java apps (on Amazon Corretto) + AWS EC2 A1 Instances on Amazon Elastic Container Services is an awesome and cost effective combination !!

Mani
4 min readOct 21, 2019

I thought for some time on what the title of this blog should be, did not want it to be just a click bait, but rather something that can differentiate from my two other blogs on Amazon Corretto and AWS EC2 A1 which were two blogs introducing Corretto with AWS Fargate and running a GO based app on EC2 A1 instances !!

This blog builds on them, and is a quick look at running a simple Java app using Amazon Corretto as the JDK runtime running on an Amazon ECS cluster with EC2 A1 Instances.

A brief recap:

Amazon Corretto — From https://aws.amazon.com/blogs/compute/running-java-applications-on-amazon-ec2-a1-instances-with-amazon-corretto/ — “Amazon Corretto is a no-cost, multiplatform, production-ready distribution of the Open Java Development Kit (OpenJDK). Production-ready Linux builds of JDK8 and JDK 11 for the 64-bit Arm architecture were released Sep 17, 2019. Scale-out Java applications can get significant cost savings using the Arm-based Amazon EC2 A1 instances.”

EC2 A1 instances — From https://aws.amazon.com/blogs/compute/running-java-applications-on-amazon-ec2-a1-instances-with-amazon-corretto/ — “ Amazon EC2 A1 instances powered by AWS Graviton Processors that feature 64-bit Arm Neoverse cores and custom silicon designed by AWS. The A1 instances deliver up to 45% cost savings for scale-out and Arm-based applications such as web servers, containerized microservices, caching fleets, distributed data stores, and Arm-native software development workflows that are supported by the extensive, and growing Arm software ecosystem”. More details on the A1 instance are available at https://aws.amazon.com/blogs/compute/getting-started-with-the-a1-instance/

Pricing:

The on-demand prices of EC2 A1 instance in the AWS Mumbai region as shown today — October 21st 2019 using the AWS Simple Monthly calculator — https://calculator.s3.amazonaws.com/index.html

OnDemand EC2 A1 prices in AWS Mumbai Region

As you can see, the prices are extremely attractive ..

Cranking up the Java app on EC2 A1 Instances on Amazon ECS

The steps are similar to what I used to test the Java app on AWS Fargate in my blog https://medium.com/@cmani/would-you-like-to-have-corretto-with-that-345c15db3073

Step 1:

Launch a EC2 A1 instance for building and deploying the Java app. The application is bare bones Spring boot app to display the JDK runtime and Operating system details:

application code
sudo amazon-linux-extras enable corretto8
sudo yum install java-1.8.0-amazon-corretto-devel
sudo yum install git
sudo yum install awscli
$ java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment Corretto-8.232.09.1 (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM Corretto-8.232.09.1 (build 25.232-b09, mixed mode)
<< setup AWS CLI with your AWS access keys>>git clone https://github.com/cmanikandan/aws-ecs-a1-corretto
cd aws-ecs-a1-corretto
./gradlew build

Step 2:

Build and push the docker image to Amazon ECR

Dockerfile:FROM amazoncorretto:8
VOLUME /tmp
COPY ./build/libs/gs-spring-boot-docker-0.1.0.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
Build and push the image to ECR:$(aws ecr get-login --no-include-email --region us-east-2)
docker build -t ecs-a1-corretto .
docker tag ecs-a1-corretto:latest xxx.dkr.ecr.us-east-2.amazonaws.com/ecs-a1-corretto:latest
docker push xxx.dkr.ecr.us-east-2.amazonaws.com/ecs-a1-corretto:latest

Step 3:

Create a Amazon ECS cluster and make sure you select EC2 A1 instances as part of the cluster. Create a Task definition using the ECR image that was pushed earlier and create an ECS service or a Task for this task definition. These steps are well covered in https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_GetStarted_EC2.htm

Access the ECS service via its endpoint like an Application Load Balancer or the Task IP address to confirm the JDK version and the Operating system details from the Java.system properties ..

In conclusion, EC2 A1 instances deliver significant cost savings for scale-out and Arm-based workloads. These include applications such as web servers, containerized microservices, caching fleets, and distributed data stores that are supported by the extensive Arm ecosystem. And what better endorsement than from the Designer of Java and a member of the Amazon team, Dr James Gosling himself ;-)

https://twitter.com/errcraft/status/1182392199503237120

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Mani
Mani

Written by Mani

Principal Solutions Architect at AWS India, and I blog/post about interesting stuff that I am curious about and which is relevant to developers & customers.

No responses yet

Write a response