python - 与 AWS Chalice 一起使用时自定义授权程序不起作用

标签 python aws-lambda aws-api-gateway chalice lambda-authorizer

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

当我尝试从 API 网关控制台附加授权者时,它工作正常。当从代码附加授权者时,它不会给出任何错误。我尝试检查 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 函数。当我触发端点时,它给出以下错误:

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

Http method: GET

Error Code: 500.

Error body: { "message": null }

我怎样才能实现这个目标。请向我提供正确的情报。

最佳答案

查看此问题:https://github.com/aws/chalice/issues/670#issuecomment-573637135

或者,还有一个解决方法

  1. 打开 AWS 控制台
  2. 转到 Amazon API Gateway,
  3. 点击右侧的“授权者”
  4. 点击“编辑”授权人
  5. 点击“保存”并再次测试。

关于python - 与 AWS Chalice 一起使用时自定义授权程序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56934676/

相关文章:

python - Python中的多线程诅咒输出

amazon-web-services - AWS API网关: Create one API for both public access and private access

amazon-web-services - 具有 IAM 权限的 Cognito 组

amazon-web-services - AWS : Why isn't my lambda function URL returning CORS headers for my preflight requests?

aws-lambda - Lambda 的参数存储与加密环境变量

aws-api-gateway - 对 API Gateway 的集成响应映射模板的任何修改都会导致 500 错误

python - 如何在随机选择函数中选择两个实例?

python - 如何将 Spark Streaming 与 TensorFlow 集成?

python - 如何将文件名作为参数传递到我的模块中?

node.js - 除非回调有延迟,否则从 AWS Lambda 将数据推送到 firebase 将不起作用