0

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?

1
  • I solved missing authentication token error (my question was earlier like this, and i am modified with current error now) by adding access key, secret key in Authorization section of Postman. I get another error: { "message": "No method found matching route mmtDemoFunction/searchAll for http method GET." } But, I have searchAll() method in my uploaded spring boot jar file which runs as Lambda function. Earlier, I was able to test like Function url with /searchAll GET method successfully. Commented Jul 12, 2023 at 4:34

1 Answer 1

1

Based on your AWS Lambda install log:

[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

the correct path to your new endpoint is /mmtFunction/searchAll.

From your error message ("No method found matching route mmtDemoFunction/searchAll for http method GET."), you look to be using incorrect app context. It should be mntFunction based on the way your lambda was installed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.