0

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

Luffy
  • 1
  • 1
  • 3
  • 1
    Can you provide more information on your issue? Like what did you do to migrate from Spring Boot 2 to Spring Boot 3? Did you modify the rest of your application accordingly? Or can you add more of your pom.xml file to see if your other dependencies are actually compatible with SB 3? You can create an issue on the GitHub repository of the project, for easier interaction: https://github.com/awslabs/aws-serverless-java-container – Renato Aug 09 '23 at 23:34

0 Answers0