ELB not able expose 2 services - spring-boot

I have one spring-boot and one react app deployed on 1 ec2 instance.
I am trying to expose both to public internet via and ELB.
Spring-boot runs on 8080 port. eg localhost:8080/v1/api**
react app runs of 3000 port. eg. localhost:3000
I would like to expose them both using Elastic Load balancer on aws.
I have 2 target group created.
one maps / --> this is mapped to the springboot app.
another one maps to /index.html
But it not able to resolve.

Related

Spring Cloud: High Availability for Eureka & API Gateway is failing

I am trying to design/POC on high availability architecture using spring cloud gateway and eureka. on local machine my entire setup is working fine with two eureka, two api gateway & two microservices nodes. Also we have created two AWS load balancer for two eureka & api gateway instances respectively. Entire setup is working fine on local machine but the whole setup is not working when we deploy same on UNIX environment.
Basically we have deployed each instance of eureka, api gateway & microservice on X & Y unix servers. and if we do request from gateway load balancer on unix server then its blocking and throwing 500 on web console.
Note - We have peered connection between two eureka instances. for more info https://medium.com/swlh/spring-cloud-high-availability-for-eureka-b5b7abcefb32
I'm adding microservice architecture screenshot for more understanding. we have to achieve high availability if in case any service is down from both the servers then application would be accessible any time.

Spring DiscoveryClient in local environment

Assuming I have two services: customerService and orderService. Both are Springboot applications contained in its own dockerfile.
In production they should be managed using Kubernetes. So there could be mutliple instances of each service. As the services should be able to call each other via REST I want to use ServiceDiscovery to get the destination of a service instance of the respective other type (e.g. customerService wants to get host, port, etc. of a running orderService instance).
I want to achieve this by using an injected DiscoveryClient in my Spring Boot services.
I understand how this works in production as there is the Kubernetes cluster the DiscoveryClient communicates with.
But how does this work in a local environment where there is no Kubernetes but only Docker running?
I think you should be looking into Kubernetes services instead of using an injected Discovery client.
For Service discovery and load-balancing, you can use Services in Kubernetes. From Kubernetes documentation:
An abstract way to expose an application running on a set of Pods as a
network service. With Kubernetes, you don't need to modify your
application to use an unfamiliar service discovery mechanism.
Kubernetes gives Pods their own IP addresses and a single DNS name for
a set of Pods and can load-balance across them.
By this, you can also avoid the overhead of maintaining discovery server instances and their availability.
How does this work in a local environment where there is no Kubernetes but only Docker running?
You can use spring profiles for picking this URL based on your environment.
For example, you'll have two spring configuration files (application-dev, application-prod) and in the dev file the URL for the second application would be localhost relative and in the prod file, the URL would be the DNS which you'll get as a part of Kubernetes service setup. So use the profile dev while running in local and prod while running in production(or an appropriate profile for your Kubernetes environment).

ECS service communication with spring microservices and AWS cloudmap

I am using the ECS Fargate launch type.
I am deploying Spring based microservices.
Every service registers itself to AWS CloudMap.
Now I am trying to communicate between two microservices using the RestTemplate.
I call the services by their DNS endpoint (e.g.: auth.mynamespace.local:8080/login). I get a 404 response every time. The security groups around the microservices are transparent on port 8080 for the corresponding inbound group.
One note: Everything is private. I don't associate a public IP and also the CloudMap namespace (R53 hosted zone) is a private one.
I really can't get behind why I am getting all those 404 errors with my RestTemplate.postForEntity(...).

How to point spring boot java app to subdomain?

i'm very new to AWS and currently having issues with domain and subdomain for my app.
I'm trying to host my Java Spring Boot web application as REST API and Angular app as front end on AWS EC2 instance. I want my Angular to run on port and be accessible via example.com and my java app to be accessible via api.example.com.
I've connected domain from godaddy to my Elastic IP already, and created Hosted zone in Route 53 for subdomain and added nameservers to domain on godaddy. Currently i'm waiting for propagation, and I assume that once I run angular on port :80, it will be accessible via example.com.
But how to point java app to api.example.com ?
As spring boot is using embedded tomcat, where should I set up a link between port and subdomain?
Thank you for your help.

AWS EC2 - not able to trigger spring boot webservice from outside but running fine in local host

I am running a spring boot web app for restful sevices in ec2 windows. It is working fine local host. I am using port 8083. But not able to trigger s3rvices from outside.
I have opened port 8083 in security group as TCP.
Plz help..What could be issue.
Same EC2 has .Net web application running and it is working fine and able to access from outside.
Ensure that 8083 port is open for inbound and outbound properties in security groups of ec2 instance.
Refer this to do the same.
How to open a web server port on EC2 instance

Resources