0

My goal here is to deploy two spring boot services using AWS ECS Fargate in a private subnet and access them via AWS API Gateway. Basically, I want to use a single HTTP API and then based on the path it should call the appropriate service. I am using VPC Links, and Cloud Map for linking services running in a private subnet, for service discovery. First of all - Is this assumption even correct, i.e. can we use a single HTTP API to call two different services based on a path?

Some considerations of how I created the ECS services.

  1. ECS Service A is deployed in a private subnet, it has no public IP enabled and the service discovery has been enabled. While enabling service discovery I choose the DNS record type to be SRV, giving a port number and TTL as 60 secs.
  2. ECS Service B is also deployed similarly.
  3. Both ECS Service A and B have a separate Service discovery endpoint.

Now in the API Gateway, the steps I followed were

  1. Created a new HTTP API using the defaults, this means the default stage and no routes and integrations configured yet.
  2. Then I created a VPC Link for HTTP API by assigning it a name (service-a-vpclink), assigning a VPC, subnet and appropriate security group (security that was assigned to the ECS service for service A).
  3. Now I created a route where the method is "ANY" and the path is "$default" and assigned an integration to it, I am able to reach all my endpoints of service A running in the private subnet. (So all good here, as this shows that I am able to reach the service running in a private subnet using API Gateway.)

For the integration that I mentioned in point 3, this was of type "Private Resource", target service as "Cloud Map" and then selecting the namespace and appropriate service (serviceA) along with the VPC link that was created in step 2.

But this is what I don't want to do. I want something like the below:
enter image description here

  1. Hitting any endpoint like "https://uzhgtf6t8u.execute-api.eu-west-2.amazonaws.com/serviceA/any-serviceA-endpoints" where /serviceA is a path that is configured in API Gateway and then any-serviceA-endpoints are the actual endpoints configured in the backend service running, navigates to service A endpoints.
  2. Hitting any endpoint like "https://uzhgtf6t8u.execute-api.eu-west-2.amazonaws.com/serviceB/any-serviceB-endpoints" where /serviceB is a path that is configured in API Gateway and then any-serviceB-endpoints are the actual endpoints configured in the backend service running, navigates to service B endpoints.

Here I attach separate integrations to path /serviceA and to path /serviceB, but this does not work. Rather this way the response is 404, not found.

What exactly am I not following?

Many thanks..

Screenshot of route enter image description here

Loui
  • 533
  • 17
  • 33
  • You've provided a lot of setup/configuration info, but almost zero debugging info. You need to enable CloudWatch Logs in API Gateway by following this: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-logging.html. Then include those logs, as well as the logs from your Spring Boot application, for the failed request that returns 404. Those logs would be critical information necessary to understand why a 404 is being returned. – Mark B Jun 02 '22 at 13:46
  • alright Mark, thanks for the hint. – Loui Jun 03 '22 at 10:23

0 Answers0