How to get a public hostname for a Java application in AWS Fargate?

538 views Asked by At

I have a simple Java application listening on port 8443. I've deployed it as a Docker image into Fargate, it has a public IP address and I can access it through the IP address just fine.

The problem is every time I redeploy the image, it gets a new IP address.

I would like to have a static hostname. For example, when I use Elastic Beanstalk and deploy a website, it will get a hostname. How do I get the same thing?

I've been following the documentation for one whole day and didn't make any progress. I've created load balancers, targets, listeners, accelerators, nothing seems to work. For example, when creating a load balancer, it doesn't tell me what the hostname is.

I'm pretty sure this is supposed to be something really easy, but I just cannot figure it out. What am I doing wrong?

1

There are 1 answers

3
Ervin Szilagyi On BEST ANSWER

You may want to create an Application Load Balancer and register your Fargate services into a Target Group for the load balancer. You have to register your services only once, if you redeploy newer versions afterwards, they will be automatically added to the Target Group.

The Application Load Balancer will provide a publicly accessible hostname. Example:

enter image description here

For your load balancer to be reachable, it needs to be in a public subnet. It also needs to have a security group which allow traffic from the public internet and also allows traffic to the registered targets.

Steps to create an ALB for your ECS cluster: AWS docs

Registering ECS services into a Target Group: AWS docs

Update:

The problem is that when I create a Target Group I cannot associate it with the service.

When you create the cluster, the AWS console asks you if you would want to deploy your containers in a VPC. You have to select yes, and create a VPC: enter image description here

Afterwards, you may want to get the id of the VPC (for example, in my case: vpc-0e6...) and you may want to go into your EC2 console an create a new Application Load Balancer, placing it into that VPC enter image description here

ALB:

enter image description here

Now, when you create a new Fargate service, you should see the Application Load Balancer:

enter image description here