How to deploy a kotlin (java) app on AWS fargate

point

--If the amount of memory specified in "Task memory" in the task definition of fargate is exceeded, the task will be forcibly terminated. --Therefore, it is necessary to adjust the maximum heap size etc. so that it does not exceed the task memory.

environment

--Language: Kotlin --Framework: ktor --docker image: openjdk: 8-jre-alpine

Dockerfile

FROM openjdk:8-jre-alpine

ENV APPLICATION_USER ktor
RUN adduser -D -g '' $APPLICATION_USER

RUN mkdir /app
RUN chown -R $APPLICATION_USER /app

USER $APPLICATION_USER

COPY ./build/libs/my-application.jar /app/my-application.jar
WORKDIR /app

CMD ["java", "-server", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-XX:InitialRAMFraction=2", "-XX:MinRAMFraction=2", "-XX:MaxRAMFraction=2", "-XX:+UseG1GC", "-XX:MaxGCPauseMillis=100", "-XX:+UseStringDeduplication", "-XX:MaxMetaspaceSize=256M", "-XshowSettings:vm", "-jar", "my-application.jar"]

Basically [ktor documentation](https://jp.ktor.work/quickstart/quickstart/docker.html#docker%E3%82%A4%E3%83%A1%E3%83%BC%E3% Based on 82% B8% E3% 81% AE% E6% BA% 96% E5% 82% 99), but added a java option.

---XX: MaxMetaspaceSize = 256M: It is a setting that secures the maximum value of the metaspace of 256MB and does not increase it any more. By default, it can be expanded without limit, so I set the maximum value just in case. ---XshowSettings: vm: Outputs VM settings at startup.

fargate task definition

Be sure to specify the memory hard limit in the container definition. The value specified here is passed to the --memory option of docker run. Normally, specify the same value as the task memory.

スクリーンショット 2020-08-27 16.08.00.png

Check task log

View the Fargate task log and make sure that Max. Heap Size is what you expected. In this case, the hard limit is 1000MiB and the java option is "-XX: MaxRAMFraction = 2", so 500M is correct.

スクリーンショット 2020-08-27 15.39.23.png

reference

-Ktor Quick Start: Docker

Recommended Posts

How to deploy a kotlin (java) app on AWS fargate
How to deploy a simple Java Servlet app on Heroku
How to deploy a container on AWS Lambda
How to get inside a container running on AWS Fargate
How to deploy a Rails application on AWS (article summary)
Deploy a Java web app on Heroku
How to deploy on heroku
How to deploy Java to AWS Lambda with Serverless Framework
[Java] How to execute tasks on a regular basis
I want to play a GIF image on the Andorid app (Java, Kotlin)
How to deploy jQuery on Rails
How to deploy Laravel on CentOS 7
[Java] How to update Java on Windows
How to make a Java container
How to deploy Bootstrap on Rails
[Java] How to create a folder
How to develop and register a Sota app in Java
How to make a Java array
How to automatically operate a screen created in Java on Windows
How to create a web server on an EC2 instance on AWS
How to check Java installed on Mac
How to make a Java calendar Summary
A memorandum on how to use Eclipse
How to redo a deployment on Heroku
[Introduction to Java] How to write a Java program
Deploy Java Servlet app locally on Tomcat
How to switch Java versions on Mac
How to make a Discord bot (Java)
How to print a Java Word document
How to send push notifications on AWS
How to deploy
How to make an app with a plugin mechanism [C # and Java]
Deploy Java web app to Azure with maven
How to use Java framework with AWS Lambda! ??
How to save images on Heroku to S3 on AWS
How to convert a solidity contract to a Java contract class
Deploy Rails to ECS Fargate with AWS Copilot
How to build a Pytorch environment on Ubuntu
[Java] Memo on how to write the source
How to write Java String # getBytes in Kotlin?
How to deploy a system created with Java (Wicket-Spring boot) to an on-campus server
Memo to build a Servlet environment on AWS EC2
How to create a Java environment in just 3 seconds
How to run the SpringBoot app as a service
Submit a job to AWS Batch with Java (Eclipse)
How to jump from Eclipse Java to a SQL file
How to deploy to Heroku from a local docker image
java: How to write a generic type list [Note]
[Java] How to play rock-paper-scissors (equivalent to paiza rank A)
List how to learn from Docker to AKS on AWS
How to make JavaScript work on a specific page
How to create a data URI (base64) in Java
[Java] How to get a request by HTTP communication
As of April 2018 How to get Java 8 on Mac
How to play YouTube videos directly on iOS app
[Java] How to cut out a character string character by character
[Java] How to erase a specific character from a character string
How to convert A to a and a to A using AND and OR in Java
How to convert a file to a byte array in Java
How to run Java EE Tutial on github on Eclipse
How to get started with creating a Rails app