AWS Serverless Java container

AWS Serverless Java container

The AWS Serverless Java Container is a library that allows you to run Spring and Spring Boot applications inside AWS Lambda. It acts as a proxy and translator between the AWS Lambda runtime and the Spring framework. It translates incoming events from Amazon API Gateway or Application Load Balancers into cloud function method invocations.

The Container processes requests in the following way:

internal life cycle java container

  1. Event Trigger: AWS Lambda receives an event that triggers the function execution.
  2. Lambda Handler Invocation: The AWS Lambda runtime invokes the configured handler class.
  3. FunctionInvoker Activation: The handler delegates the event processing to the FunctionInvoker.
  4. Function Resolution & Input Adaptation:
    1. FunctionInvoker identifies and loads the appropriate Spring Cloud Function bean from the application context. It uses the SPRING_CLOUD_FUNCTION_DEFINITION environment variable to look up the bean in the ApplicationContext. If this variable is missing, it tries to find a single bean of type Function, Consumer, or Supplier.
      ℹ️
      The first time the container starts, the FunctionInvoker triggers the Spring Boot startup sequence. This ensures that when the “Event Trigger” happens, the beans are already “warm” and ready for resolution, though the very first request will still bear the “Cold Start” penalty of booting the entire Spring framework. If your Spring Boot app takes longer than 10 seconds to start, the container can boot it in a background thread to prevent Lambda from timing out during the cold start.
    2. FunctionInvoker converts the incoming Lambda event payload into the input type expected by the function.
  5. Function Execution: The resolved function executes with the adapted input.
  6. Output Adaptation & Response: FunctionInvoker converts the function’s output into a format suitable for Lambda responses. This response is returned back through the Lambda runtime to the event source.

The FunctionInvoker acts as the vital adapter component connecting AWS Lambda’s native event-driven model with Spring Cloud Function’s Java-based functional programming model, orchestrating input/output transformations and function invocation seamlessly in the internal lifecycle.