I have Spring boot application uploaded on AWS Lambda via S3.
As per my requirement, I have to use this as API Gateway end point. So, I tried adding it like below on the Lambda console:
I clicked on "Add Trigger" Chose "API Gateway" Create a New API Selected "REST API" Security is "Open" Added
I got an API API Gateway REST end point, when i tested using Postman, i got error: "message": "No method found matching route mmtDemoFunction/searchAll for http method GET."
Spring boot code:
public class AWSLambdaHandler implements RequestStreamHandler {
private SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
public AWSLambdaHandler() throws ContainerInitializationException {
handler = (SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse>) new SpringBootProxyHandlerBuilder()
.springBootApplication(AWSTestApplication.class)
.defaultProxy()
.asyncInit()
.buildAndInitialize();
}
@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);
}
}
RestController:
@RestController
public class AWSTestController {
@Autowired
private MMTServiceDAO mmtServiceDAO;
@CrossOrigin(origins = "*")
@GetMapping("/searchAll")
public List<MMTData> searchAll() {
List<MMTData> dataList = mmtServiceDAO.findAll();
return dataList;
}
@CrossOrigin(origins = "*")
@GetMapping("/searchDataByMember/{memberno}")
public List<MMTData> searchDataByMember(@PathVariable Integer memberno) {
List<MMTData> dataList = mmtServiceDAO.findDataByMemberNo(memberno);
return dataList;
}
}
API Gateway:
[mmtFunction-API](https://us-east-2.console.aws.amazon.com/apigateway/home?region=us-east-2#/apis/7ocfwgjy5b/resources/ymsdok/methods/ANY)
arn:aws:execute-api:us-east-2:383322123415:7ocfwgjy5b/*/*/mmtFunction
API endpoint: https://7ocfwgjy5b.execute-api.us-east-2.amazonaws.com/default/mmtFunction
Details
API type: REST
Authorization: NONE
Method: ANY
Resource path: /mmtFunction
Service principal: apigateway.amazonaws.com
Stage: default
Statement ID: lambda-937e9b59-282a-4ff8-af14-717eaa623d85
Spring boot code:
public class AWSLambdaHandler implements RequestStreamHandler { private SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
public AWSLambdaHandler() throws ContainerInitializationException {
handler = (SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse>) new SpringBootProxyHandlerBuilder()
.springBootApplication(AWSTestApplication.class)
.defaultHttpApiV2Proxy()
.asyncInit()
.buildAndInitialize();
}
@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);
}
}
@RestController
public class AWSTestController {
@Autowired
private MMTServiceDAO mmtServiceDAO;
@CrossOrigin(origins = "*")
@GetMapping("/searchAll")
public List<MMTData> searchAll() {
List<MMTData> dataList = mmtServiceDAO.findAll();
return dataList;
}
@CrossOrigin(origins = "*")
@GetMapping("/searchDataByMember/{memberno}")
public List<MMTData> searchDataByMember(@PathVariable Integer memberno) {
List<MMTData> dataList = mmtServiceDAO.findDataByMemberNo(memberno);
return dataList;
}
}
Could someone please help how to solve this issue?