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!