执行 API 方法时未调用 AWS API Gateway Custom Authorizer

AWS API Gateway Custom Authorizer is not invoked when executing API Method

我正在使用 AWS lambda 无服务器 WEB API 应用程序。我的控制器有一种方法可以简单地 returns 一些字符串值。我想添加一个身份验证层来验证请求者。请求者应将 "Authorizer" 密钥传递给 header 以进行身份​​验证。

This article help me to do so. I used this example.

我创建了一个 Custom Authorizer lambda,用于验证在 API 请求的 header 中传递的用户。但是当我点击 API URL 时,我的自定义授权者没有调用。下面是我的 Custom Authorizer lambda 函数代码

public APIGatewayCustomAuthorizerResponse FunctionHandler(APIGatewayCustomAuthorizerRequest apigAuthRequest, ILambdaContext context)
    {


        Console.WriteLine("1");

        bool ok = false;

        if (apigAuthRequest.Headers["Authorization"] == "test")
        {
            ok = true;
            Console.WriteLine("2");
        }
        return new APIGatewayCustomAuthorizerResponse
        {
            PrincipalID = "test",
            PolicyDocument = new APIGatewayCustomAuthorizerPolicy
            {
                Version = "2012-10-17",
                Statement = new List<APIGatewayCustomAuthorizerPolicy.IAMPolicyStatement>() {
                  new APIGatewayCustomAuthorizerPolicy.IAMPolicyStatement
                  {
                       Action = new HashSet<string>(){"execute-api:Invoke"},
                       Effect = ok ? "Allow" : "Deny",
                       Resource = new HashSet<string>(){ apigAuthRequest.MethodArn } // resource arn here
                  }
            },
            }
        };

    }

我希望在调用 API.

时调用此函数

下面是 AWS 控制台的屏幕截图 --> API 网关,我在其中为 API 配置了自定义授权方。

为什么当我点击 API URL.

时,我的授权者没有被调用

自定义授权器仅在您部署阶段后才开始工作。确保你部署了你的。