簡體   English   中英

與 AWS Chalice 一起使用時自定義授權程序不起作用

[英]Custom Authorizer not working when used with AWS Chalice

我正在使用 AWS 自定義授權程序來保護 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 }

我怎樣才能做到這一點。 請向我提供適當的情報。

看到這個問題: https : //github.com/aws/chalice/issues/670#issuecomment-573637135

或者,有一個解決方法

  1. 打開 Aws 控制台
  2. 轉到亞馬遜 API 網關,
  3. 在右側單擊“授權人”
  4. 點擊“編輯”授權人
  5. 單擊保存並再次測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM