自定义授权者 + 阶段配置值

Custom Authorizer + Stages configuration values

我们在 API 网关中配置了 Auth0 的自定义授权方。我们希望它根据调用它的阶段加载不同的配置值。有已知的方法来处理这个问题吗?

您有 2 个选择:

  1. 如果你想对两个阶段使用相同的授权函数,你可以解析包含阶段的input passed to the function

    {
      "type":"TOKEN",
      "authorizationToken":"<caller-supplied-token>",
      "methodArn":"arn:aws:execute-api:<regionId>:<accountId>:<apiId>/<stage>/<method>/<resourcePath>"
    }
    
  2. 如果你想在每个阶段使用不同的函数,你可以使用阶段变量。 注意:您将必须使用 CLI 或 SDK 添加带有阶段变量的授权方。 CLI 示例:

    aws apigateway update-authorizer --rest-api-id <apidId> --authorizer-id <authorizerId> --patch-operations '[{"op":"replace","path":"/authorizerUri","value":"arn:aws:apigateway:<region>:lambda:path/2015-03-31/functions/arn:aws:lambda:<region>:<accountId>:function:${stageVaribles.authorizer}/invocations"}]'