我正在使用 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
或者,还有一个解决方法
- 打开 AWS 控制台
- 转到 Amazon API Gateway,
- 点击右侧的“授权者”
- 点击“编辑”授权人
- 点击“保存”并再次测试。
关于python - 与 AWS Chalice 一起使用时自定义授权程序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56934676/