Spring Cloud Gateway on AWS

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

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật