2

我正在使用 AWS Custom Authorizer 来保护 lambda 函数。由于一些配置问题,我无法使用自定义授权方。

当我尝试从 API Gateway 控制台附加授权方时,它工作正常。当授权人从代码中附加时,它不会给出任何错误。我尝试检查 cloudwatch 日志,没有为 lambda 函数生成日志(对于授权者和 helloworld 函数)。

以下是我编写的示例代码:

from chalice import Chalice
from chalice import CustomAuthorizer
app = Chalice(app_name='helloworld-python')

authorizer = CustomAuthorizer(
    'MyCustomAuth', header='Authorization',
    authorizer_uri=('arn:aws:apigateway:{region}:lambda:path/2015-03-31'
                    '/functions/arn:aws:lambda:{region}:{account-id}:'
                    'function:{function-name}/invocations'))

@app.route('/test/test_authorizer', authorizer=authorizer)
def index():
    return {'hello': 'world'}

我已配置以下策略:

{
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Action": [
          "execute-api:Invoke"
        ],
        "Resource": [
          "*"
        ]
      }
    ]
  }

我无法将授权方添加到 lambda 函数。当我触发端点时,它给了我以下错误:

端点:https://{rest-api-id}.execute-api.{region}.amazonaws.com/dev/test/test_authorizer

Http方法:GET

错误代码:500。

错误正文:{ "message": null }

我怎样才能做到这一点。请给我正确的情报。

4

1 回答 1

1

看到这个问题:https ://github.com/aws/chalice/issues/670#issuecomment-573637135

或者,有一个解决方法

  1. 打开 AWS 控制台
  2. 转到亚马逊 API 网关,
  3. 在右侧单击“授权人”
  4. 点击“编辑”授权人
  5. 单击保存并再次测试。
于 2020-01-15T12:51:37.380 回答