AWS serverless java container spring boot 2 to spring boot 3

563 Views Asked by At

Below code is working in spring boot 2 using aws-serverless-java-container-springboot2

I tried using aws-serverless-java-container-springboot3 but in below apps there is no API calls/controller. Simply trying to init the bean so that aws lamba can be triggered.

Doesn't have proper sample to convert from aws-serverless-java-container-springboot2 to aws-serverless-java-container-springboot3 https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spring-Boot3

<dependency>
   <groupId>com.amazonaws.serverless</groupId>
   <artifactId>aws-serverless-java-container-springboot3</artifactId>
   <version>2.0.0-M1</version>
</dependency>
import javax.servlet.ServletContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.amazonaws.serverless.exceptions.ContainerInitializationException;
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
import com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.ScheduledEvent;
import com.service.AKRService;

public class SvHandler implements RequestHandler < ScheduledEvent, String > {
  private static final Logger logger = LoggerFactory.getLogger(SvHandler.class);
  
  public String handleRequest(ScheduledEvent input, Context context) {
      AKRService akrSvc = null;
    try {
        akrSvc = init();
    } catch (ContainerInitializationException e) {
      logger.error("Error Initialiazing Spring Boot Container");
    }
    logger.info("Started in handleRequest");
    logger.info("Got the managed bean: {}", akrSvc);
    akrSvc.knock();
    return "Success";
  }
  protected AKRService init() throws ContainerInitializationException {
    final SpringBootLambdaContainerHandler < AwsProxyRequest, AwsProxyResponse > handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(Application.class);
    final ServletContext servContext = handler.getServletContext();
    final WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servContext);
    return ctx.getBean(AKRService.class);
  }
}

I tried using aws-serverless-java-container-springboot3 to convert existing lamba service from spring boot 2

Doesn't have proper sample to convert from aws-serverless-java-container-springboot2 to aws-serverless-java-container-springboot3 https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spring-Boot3

0

There are 0 best solutions below