0

As part of a POC, I’m using spring-cloud-function with spring-cloud-function-adapter-aws to expose a function behind an AWS ALB, that looks up a business object and returns it. However, in the event of a missing object I’m struggling to understand which function signature to use that allows me to return a 404 status code with an empty payload.

I’ve tried a few options, such as Function<APIGatewayProxyRequestEvent, Owner> and Function<APIGatewayProxyRequestEvent, Message<Owner>>. The former doesn’t let you control statusCode and headers that are returned, and the latter doesn’t let you return a Message with a null payload.

I’ve landed on Function<APIGatewayProxyRequestEvent, Message<String>> getOwnerById() which allows me to specify a statusCode and an empty string as the body, but I’m wondering if there’s a more idiomatic approach to this in spring-cloud-function that allows me to return an empty body?

Ideally, I’d just like to return a APIGatewayProxyResponseEvent, which I’d have full control of and would bypass all post-function response conversion.

I have my solution in GitHub, with the function and a test which reproduces the issue https://github.com/foyst/spring-petclinic-rest-serverless/blob/1-spring-cloud-function/src/main/java/org/springframework/samples/petclinic/lambda/LambdaConfig.java https://github.com/foyst/spring-petclinic-rest-serverless/blob/1-spring-cloud-function/src/test/java/org/springframework/samples/petclinic/lambda/LambdaConfigTests.java

Thanks in advance!

foyst
  • 1
  • Have you tried simply throwing an exception from the method? – Oleg Zhurakousky Jul 21 '21 at 10:22
  • Hey Oleg, I've tried throwing an exception using all the function variations I mentioned and they're all unhandled, which results in ALB returning a 502. – foyst Jul 21 '21 at 21:58
  • This sounds like a bug or at best missing feature. Could you please raise an issue here - https://github.com/spring-cloud/spring-cloud-function/issues and you can link to this post – Oleg Zhurakousky Jul 22 '21 at 14:52
  • Thanks for your support on this Oleg, I've raised it as https://github.com/spring-cloud/spring-cloud-function/issues/716 – foyst Jul 22 '21 at 22:22

0 Answers0