Search code examples
spring-bootaws-lambdaspring-data-jpaaws-api-gateway

Spring data jpa with AWS Lambda


Iam new to AWS lambda and trying to create deploy my existing Spring boot with Spring data application in lamda, i have my API endpoints exposed,

@RequestMapping(value = "symbols/{id}", method = RequestMethod.GET)
private Symbols getSymbolById(@PathVariable int id) {
    System.err.println("Logged");
    Optional<Symbols> symbol = symbolsRepo.findById(id);
    return symbol != null ? symbol.get() : null;
}

And by following the below link, i came to know that, we can deploy our API endpoints in lambda, and using API gateway created with HTTP protocal,

enter image description here

https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/springboot2/pet-store

We can access our endpoint. Iam facing challenges in accessing DB using Spring data jpa. I have done the below configuration,

spring:
  datasource:
    url: {DB_URL}
    username: {UserName}
    password: {Password}

In my local environment it is working, but if i deploy the application by packaging it as zip and deploying it in Lambda, i couldnt able to get the response from API gateway.

Am getting "message": "Service Unavailable" exception

Can anyone let me know, what are the steps to deploy a spring boot application to Lambda?

Also suggest, what programming language we can use, to retrieve data from DB, with Pagination sorting and other features as how Spring Data jpa provides, but can be easier to deploy in lambda.


Solution

  • You may have hit a bug that has been fixed in the recent AWS Serverless Container 2.0.0 release. We also included test cases for Spring Data JPA now so I strongly suggest to retry with the latest version.