Somehow, I’m having trouble getting Spring Cloud Gateway to work on AWS. It works fine locally, but after deployment to AWS, it doesn’t. I think I need another pair of eyes on this.
I have a simple routing configuration:
@Configuration
public class GatewayConfig {
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
return builder.routes()
.route("test_route", r -> r.path("/get")
.uri("http://httpbin.org"))
.route("tasks_route", r -> r
.path("/v3/tasks/**")
.filters(f -> f.stripPrefix(1))
.uri("http://tasksapi-********.us-west-2.elb.amazonaws.com"))
.build();
}
}
and a very simple TaskController on another microservice:
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/tasks")
public class TaskController {
private final TaskRepository repository;
@GetMapping
public List<Task> all() {
log.debug("Returning Tasks");
return repository.findAll(Sort.by("id").ascending());
}
}
When I send requests to configured uris it returns 504 on AWS and works just as expected locally. Requesting Gateway’s root works well, Tasks microservice is also accessable, so Gateway and TasksAPI are exposed to the internet and works well.
So it seems something with outbound/returned connection from the Cloud Gateway that I cannot figure out yet.
I’ve play with security groups config, even all traffic allowed / all ports allowed – did not work.
What I see in a Gateway logs:
it mapped path:
[API Gateway] [ctor-http-nio-4] o.s.c.g.h.p.PathRoutePredicateFactory : Pattern "/get" matches against value "/get"
[API Gateway] [ctor-http-nio-4] o.s.c.g.h.RoutePredicateHandlerMapping : Mapping [Exchange: GET http://apigateway-******.us-west-2.elb.amazonaws.com/get] to Route{id='test_route', uri=http://httpbin.org:80, order=0, predicate=Paths: [/get], match trailing slash: true, gatewayFilters=[], metadata={}}
and tried to bypass the request:
[API Gateway] [ctor-http-nio-4] g.f.h.o.ObservedRequestHttpHeadersFilter : Will instrument the HTTP request headers [X-Forwarded-For:"73.170.2.16,172.31.33.114", X-Forwarded-Proto:"http,http", X-Forwarded-Port:"80,80", Host:"apigateway-******.us-west-2.elb.amazonaws.com", X-Amzn-Trace-Id:"Root=1-665b4222-314b183f051606b16ae8ce60", Accept:"application/json", User-Agent:"Apache-HttpClient/4.5.14 (Java/17.0.8.1)", Accept-Encoding:"br,deflate,gzip,x-gzip", X-MEMBER-UUID:"88888888-4444-4444-4444-123456789012", Forwarded:"proto=http;host=apigateway-******.us-west-2.elb.amazonaws.com;for="172.31.33.114:27256"", X-Forwarded-Host:"apigateway-******.us-west-2.elb.amazonaws.com"]
[API Gateway] [ctor-http-nio-4] g.f.h.o.ObservedRequestHttpHeadersFilter : Client observation {name=http.client.requests(null), error=null, context=name='http.client.requests', contextualName='null', error='null', lowCardinalityKeyValues=[http.method='GET', http.status_code='UNKNOWN', spring.cloud.gateway.route.id='test_route', spring.cloud.gateway.route.uri='http://httpbin.org:80'], highCardinalityKeyValues=[http.uri='http://apigateway-******.us-west-2.elb.amazonaws.com/get'], map=[class io.micrometer.core.instrument.LongTaskTimer$Sample='SampleImpl{duration(seconds)=5.9526E-5, duration(nanos)=59526.0, startTimeNanos=141966824751180}', class io.micrometer.core.instrument.Timer$Sample='io.micrometer.core.instrument.Timer$Sample@7185ff93'], parentObservation={name=http.server.requests(null), error=null, context=name='http.server.requests', contextualName='null', error='null', lowCardinalityKeyValues=[exception='none', method='GET', outcome='SUCCESS', status='200', uri='UNKNOWN'], highCardinalityKeyValues=[http.url='/get'], map=[class io.micrometer.core.instrument.LongTaskTimer$Sample='SampleImpl{duration(seconds)=0.001275558, duration(nanos)=1275558.0, startTimeNanos=141966823599918}', class io.micrometer.core.instrument.Timer$Sample='io.micrometer.core.instrument.Timer$Sample@2e1a3062'], parentObservation=null}} created for the request. New headers are [X-Forwarded-For:"73.170.2.16,172.31.33.114", X-Forwarded-Proto:"http,http", X-Forwarded-Port:"80,80", Host:"apigateway-******.us-west-2.elb.amazonaws.com", X-Amzn-Trace-Id:"Root=1-665b4222-314b183f051606b16ae8ce60", Accept:"application/json", User-Agent:"Apache-HttpClient/4.5.14 (Java/17.0.8.1)", Accept-Encoding:"br,deflate,gzip,x-gzip", X-MEMBER-UUID:"88888888-4444-4444-4444-123456789012", Forwarded:"proto=http;host=apigateway-******.us-west-2.elb.amazonaws.com;for="172.31.33.114:27256"", X-Forwarded-Host:"apigateway-******.us-west-2.elb.amazonaws.com"]
[API Gateway] [ctor-http-nio-1] r.n.http.server.HttpServerOperations : [e42e22bc, L:/172.31.30.41:8080 - R:/172.31.33.114:27258] New http connection, requesting read
[API Gateway] [ctor-http-nio-1] r.n.http.server.HttpServerOperations : [e42e22bc, L:/172.31.30.41:8080 - R:/172.31.33.114:27258] Increasing pending responses count: 1
[API Gateway] [ctor-http-nio-1] reactor.netty.http.server.HttpServer : [e42e22bc-1, L:/172.31.30.41:8080 - R:/172.31.33.114:27258] Handler is being applied: org.springframework.http.server.reactive.ReactorHttpHandlerAdapter@64471596
And nothing happens after that. Requests did not reach TasksAPI (I cannot see them in a logs, I can see incoming requests when accessing TasksAPI directly). It seems like requests cannot go outside of the Gateway application/container for some reason