I have a spring boot application that exposes a few endpoints in my onpremise infraestructure. The application uses a MongoDB Cloud cluster and has an application.properties with some aditional configurations (port, firebase key, etc.)
Which is the stardard way to expose my endpoints using AWS? I have configured an EC2 micro, with security rules to access the MongoDB cluster and the EC2 has a public URL to let the consumers use the endpoints. But I know that there are best ways to do this. I want to know the simplest and the rigth way to do, for example: if I need an API Gateway, a Load balancer and how to maintain the same URL to access to the APIS if the EC2 is restarted, etc.
The springboot application serves endpoints to an Android App, that could receive from 3 to 6 tps, sending responses with plain json text and some images in base64.
If you use the Load Balancer, then you have to create a Target Group where you can attach the Instance instead of IP address, so even if the Ec2 instance restarts the Instance Id remain the same, so the requests will be forwarded to the same instance.
Load Balancer benefits:
Can use multiple backend servers to distribute the traffic
Provides high scalability without any interruption by adding or removing instances
Handles server failures gracefully without affecting service availability.
And many other benefits.
If you use the API Gateway, then you have to create a CloudMap configuration and then integrate that to the API gateway resource/request. In the CloudMap also we have the ability to attach the instance instead of IP address. So even if the Instance restarts the Instance Id remain the same, so the requests will be forwarded to the same instance.
API Gateway benefits:
Can expose multiple APIs to the public or external consumers.
Easy to create and control API keys
Can transform the API request and response in the API gateway itself before processing.
Easy to maintain versions and canary deployment
Easy to create API documentation
And many other benefits
For both the service(API Gateway/ Load balancer) you will receive a static URL, even the instance URL or the IP changes. So you don't have to worry about instance restart.