【问题标题】:How to filter API Gateway requests for the java lambda based on the request path如何根据请求路径过滤 Java lambda 的 API Gateway 请求
【发布时间】:2021-06-12 16:32:31
【问题描述】:

我有一个与 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;
    }
}

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

【问题讨论】:

    标签: java aws-lambda aws-api-gateway amazon-api-gateway


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2023-03-06
      • 2021-02-19
      • 2020-05-08
      • 2023-03-28
      • 2020-04-06
      • 2015-12-03
      • 2020-09-09
      • 2012-06-16
      • 2017-11-30
      相关资源
      最近更新 更多