Skip to content

Post Request with springboot4 Container hangs #1598

@Vadym79

Description

@Vadym79

I have a simple example application which uses AWS Serverless Java Container for Spring Boot 4 to store and retrieve a product from DynamoDB. You can deploy it with AWS SAM.

It works, if I use my own handler implementation for the PostProductFunction (which creates a new product, see template.yaml) like this:

PostProductFunction:
Type: AWS::Serverless::Function
Properties:
Handler: software.amazonaws.example.product.handler.StreamLambdaHandler::handleRequest

If I switch the handler to use

Handler: com.amazonaws.serverless.proxy.spring.SpringDelegatingLambdaContainerHandler

and activate a required MAIN_CLASS environment variable in the Globals Function section of the SAM template like this:

Globals:
Function:
.....
Environment:
Variables:
MAIN_CLASS: software.amazonaws.Application
REGION: !Sub ${AWS::Region}
JAVA_TOOL_OPTIONS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
PRODUCT_TABLE_NAME: !Ref ProductsTable

The POST request sent from the API Gateway with Content-Type:application/json as a HTTP Header and JSON payload { "id": 1, "name": "Print 10x13", "price": 15 } as a HTTP body runs into the 30 second timeout of the API Gateway and Lambda function even if I clearly see in the Lambda logs, that the request is executed, which means that ProductController createProduct method is sucessfully finished within a few seconds (and the product is created in the DynamoDB). I don't have any control what's happening outside of the Controller method when using the SpringDelegatingLambdaContainerHandler as a handler.

If I switch from POST to PUT in the SAM template and ProductController the behavior is the same (it hangs with the com.amazonaws.serverless.proxy.spring.SpringDelegatingLambdaContainerHandler handler).

I don't have such a problem with the GET request (for example GetProductByID) which finishes successfully in time.

Please help me investigate why the problem arise? Maybe I'm doing something wrong.

ADDED : I found out how to make it work. It didn't work when createProduct method of ProductController returned void and didn't have produces mime type. Now I changed both (returning String and defined text/plain as produces mime type) and it works with com.amazonaws.serverless.proxy.spring.SpringDelegatingLambdaContainerHandler handler as well. Still it worked with returning void and not having produces mime type for POST/PUT with AWS Serverless Java Spring Boot 3 Container and Spring Boot 3 (I cheked my working examples). The most important thing: it should work the same way regardless whether I define my own StreamHandler , which works fine with return void and without produces mime type for POST/PUT or re-use the existing com.amazonaws.serverless.proxy.spring.SpringDelegatingLambdaContainerHandler handler. So please review the issue and fix it.

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