【问题标题】:Why does API Gateway not have permissions for my Authorizer lambda when using Swagger?为什么 API Gateway 在使用 Swagger 时没有我的 Authorizer lambda 权限?
【发布时间】:2018-08-03 16:24:12
【问题描述】:

我有一个使用 Swagger 定义的 API,它定义了以下 API Key 授权方:

securityDefinitions:
  api_key:
    type: apiKey
    name: x-api-key
    in: header
    x-amazon-apigateway-authtype: "oauth2"
    x-amazon-apigateway-authorizer:
      type: token
      authorizerUri: arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:[accountid]:function:ApiKeyAuthorizerLambdaFunction/invocations
      authorizerResultTtlInSeconds: 0

但是,当我将此 Swagger 定义传递到我的 CloudFormation 脚本并调用受此授权方保护的端点时,我得到一个 500。API 网关日志显示以下内容:

Incoming identity: ***key
Execution failed due to configuration error: Invalid permissions on Lambda function
Execution failed due to configuration error: Authorizer error

请注意,我 已授予 API 网关执行此 lambda 的权限:

LambdaPermissionAuthorizerApiGateway:
  Type: AWS::Lambda::Permission
  Properties:
    FunctionName:
      Fn::GetAtt:
      - ApiKeyAuthorizerLambdaFunction
      - Arn
    Action: lambda:InvokeFunction
    Principal: apigateway.amazonaws.com

事实上,当我将 Serverless 为授权端点生成的 CloudFormation 脚本(使用 Serverless 的表示法)与我自己使用 Swagger 的 CloudFormation 脚本进行比较时,我发现它们之间几乎没有区别,除了我的授权人是使用 Swagger 定义而不是直接作为 CF 资源。

任何人都可以对此有所了解吗?这是将 Swagger 与 CloudFormation 结合使用时的错误吗?

【问题讨论】:

  • 能否请您发布使用授权方的端点之一的配置?
  • 嗨,你能解决这个问题吗?我也面临同样的问题
  • 很遗憾,我认为我们没有这样做,抱歉。

标签: swagger aws-api-gateway amazon-cloudformation


【解决方案1】:

您能否尝试将x-amazon-apigateway-authorizerauthorizerCredentials 参数设置为有权执行授权方lambda 的有效IAM 角色?不确定标准 AWS::Lambda::Permission 是否适用于此,但您可能希望暂时保留它以防仍需要它。

x-amazon-apigateway-authorizer docs 显示一个示例。

【讨论】:

    猜你喜欢
    • 2019-12-25
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    • 2020-03-17
    • 2017-08-20
    • 1970-01-01
    • 2021-03-10
    • 1970-01-01
    相关资源
    最近更新 更多