Skip to content

Can't return 404 with empty payload using spring-cloud-function-adapter-aws #716

Closed
@foyst

Description

@foyst

Describe the bug
When using spring-cloud-function-adapter-aws, in the event of requesting a missing REST resource I’m struggling to understand how to return a 404 status code with an empty payload.

I’ve landed on Function<APIGatewayProxyRequestEvent, Message<String>> which allows me to specify a "statusCode" header 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 (as opposed to an empty string)?

This is what gets returned:
image

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.

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

This issue was originally raised in SO - https://stackoverflow.com/questions/68465552/how-to-handle-a-404-response-with-spring-cloud-function-and-aws

Sample
I have my example in GitHub, with the function and a test which reproduces the issue
Lambda Config
Lambda Test

Thanks, Ben

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions