0

我有一个与 API Gateway 代理集成的 Lambda 函数,这意味着它接受代理+资源作为输入。

我有一个 java Lambda 类,它接受APIGatewayProxyRequestEvent类型作为输入并将APIGatewayProxyRequestOutput作为响应/输出。

public class DashboardOrchestratorHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {

    @Override
    public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context) {
        
        APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent();
        response.setIsBase64Encoded(false);
        response.setStatusCode(200);
        HashMap<String, String> headers = new HashMap<String, String>();
        headers.put("Content-Type", "text/html");
        response.setHeaders(headers);
        response.setBody("<!DOCTYPE html><html><head><title>AWS Lambda sample</title></head><body>" +
                "<h1>Welcome</h1><p>Page generated by a Lambda function.</p>" +
                "</body></html>");
        // log execution details
        //Util.logEnvironment(event, context, gson);
        return response;
    }
}

现在我正在寻找一些关于如何根据请求路径和请求参数编排不同类的指南。

4

1 回答 1

0

您不能有多个处理程序-> https://forum.serverless.com/t/multiple-handlers-per-function/1025/2但您可以有多个可以根据事件触发的帮助程序。这是 Python 示例 -> https://stackoverflow.com/a/50688766/1737811但将其转换为 Java 或任何其他堆栈非常简单。

于 2021-03-15T12:03:55.953 回答