I created a simple example Pulumi TypeScript program that should deploy a Spring Boot application into a AWS ECS Fargate Cluster. The Spring Boot app is containerized/Dockerized with the help of Cloud Native Buildpacks/Paketo.io and published to the GitHub Container Registry at ghcr.io/jonashackt/microservice-api-spring-boot
(example project here).
I've read through some Pulumi tutorials and started with the usual pulumi new aws-typescript
. I now have the following index.ts
:
import * as awsx from "@pulumi/awsx";
// Create a load balancer to listen for requests and route them to the container.
let loadbalancer = new awsx.lb.ApplicationListener("alb", { port: 8098, protocol: "HTTP" });
// Define Container image published to the GitHub Container Registry
let service = new awsx.ecs.FargateService("microservice-api-spring-boot", {
taskDefinitionArgs: {
containers: {
microservice_api_spring_boot: {
image: "ghcr.io/jonashackt/microservice-api-spring-boot:latest",
memory: 768,
portMappings: [ loadbalancer ],
},
},
},
desiredCount: 2,
});
// Export the URL so we can easily access it.
export const apiUrl = loadbalancer.endpoint.hostname;
After selecting the dev
stack, a normal pulumi up
runs through and provides me with the ApplicationLoadBalancer URL. Here's also a asciicast I prepared to show everything runs smooth:
My problem now is that the Fargate Services are stopped and started constantly. I've looked into CloudWatch logs and I see the Spring Boot apps starting - and beeing stopped after a few seconds again. I already checked the ApplicationLoadBalancer's TargetGroup and I see the Registered Targets
becoming unhealthy
again and again. How do I fix that?