Deploy Java microservices on Amazon ECS using AWS Fargate - AWS Prescriptive Guidance

Deploy Java microservices on Amazon ECS using AWS Fargate

Created by Vijay Thompson (AWS)

R Type: N/A

Source: Containers

Target: Amazon ECS

Created by: AWS

Environment: PoC or pilot

Technologies: Websites & web apps; Containers & microservices

AWS services: Amazon ECS

Summary

This pattern provides guidance for deploying containerized Java microservices on Amazon Elastic Container Service (Amazon ECS) using AWS Fargate. The pattern doesn't use Amazon Elastic Container Registry (Amazon ECR) for container management; instead, Docker images are pulled in from the on-premises environment.

Microservices are an architectural and organizational approach to software development where software is composed of small independent services that communicate over well-defined APIs. These architectures make applications easier to scale and faster to develop, enabling innovation and accelerating time-to-market for new features.

Amazon ECS is a highly scalable, high-performance container orchestration service that supports Docker containers and allows you to easily run and scale containerized applications on AWS. 

AWS Fargate is a compute engine for Amazon ECS that allows you to run containers without having to manage servers or clusters. 

Prerequisites and limitations

Prerequisites

  • An existing Java microservices application on a Docker hub

  • A public Docker repository

  • An active AWS account

  • Familiarity with AWS services, including Amazon ECS and Fargate

  • Docker, Java, and Spring Boot framework

  • Amazon Relational Database Service (Amazon RDS) up and running (optional)

  • A virtual private cloud (VPC) if the application requires Amazon RDS (optional)

Limitations

  • Fargate is currently supported only in Amazon ECS.

Architecture

Source technology stack

  • Java microservices (for example, implemented in Spring Boot) and deployed on Docker

Source architecture

Target technology stack

  • An Amazon ECS cluster that hosts each microservice using Fargate

  • A VPC network to host the Amazon ECS cluster and associated security groups 

  • A cluster/task definition for each microservice that spins up containers using Fargate

Target architecture

Tools

Tools

  • Amazon ECS – Amazon ECS eliminates the need to install and operate your own container orchestration software, manage and scale a cluster of virtual machines, or schedule containers on those virtual machines. 

  • AWS Fargate – With the AWS Fargate compute engine, you no longer have to provision, configure, and scale clusters of virtual machines to run containers, choose server types, decide when to scale your clusters, or optimize cluster packing.  

  • Docker file – Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run, including libraries, system tools, code, and runtime. 

Docker code

The following DockerFile specifies the Java Development Kit (JDK) version that is used, where the Java archive (JAR) file exists, the port number that is exposed, and the entry point for the application.

FROM openjdk:8 ADD target/Spring-docker.jar Spring-docker.jar EXPOSE 8080 ENTRYPOINT ["java","-jar","Spring-docker.jar"]

Epics

Task Description Skills required
Create a virtual private cloud (VPC) in your AWS account.

System Admin, Developer
Create subnets inside the VPC.

A minimum of two subnets are required.

System Admin, Developer
Create an Amazon RDS DB instance (optional).

If you require Amazon RDS, create it in one of your private subnets.

System Admin, Developer
Ensure that the security group allows access to Amazon RDS (optional).

If you require Amazon RDS, ensure that the security group allows access to Amazon RDS.

System Admin, Developer
Task Description Skills required
Create a task definition.

Running a Docker container in Amazon ECS requires a task definition. Open the Amazon ECS console at https://console.aws.amazon.com/ecs/, choose "Task definitions," and create a new task definition.

System Admin, Developer
Choose launch type.

Choose Fargate as the launch type.

System Admin, Developer
Configure the task.

Define a task name and configure the application with the appropriate amount of task memory and CPU.

System Admin, Developer
Define the container.

Specify the container name. For the image, enter the Docker site name, the repository name, and the tag name of the Docker image. Set memory limits for the application, and set port mappings for the allowed ports.

System Admin, Developer
Create the task.

When the task and container configurations are in place, create the task. For detailed instructions, see the links in the References section.

System Admin, Developer
Task Description Skills required
Create and configure a cluster.

Select networking as the cluster type, configure the name, and then create the cluster.

System Admin, Developer
Configure tasks.

Go to Tasks and choose "Run new task." Configure the launch type as Fargate and select the task and the cluster you previously created. Configure the VPC, subnet, and security group to allow access.

System Admin, Developer
Task Description Skills required
Test the application.

Test the application using the public DNS, and then cut over to Amazon ECS.

System Admin, Developer