【问题标题】:How to provide AWS API Gateway Custom Authorizer a Lambda Permission?如何为 AWS API Gateway Custom Authorizer 提供 Lambda 权限?
【发布时间】:2019-12-25 14:42:54
【问题描述】:

我有一个 AWS Lambda 函数,在成功将其设置为授权方后,我尝试为其提供权限。

基本上我想在 CloudFromation 中实现以下目标 -

以下是我的 CloudFormation 资源,无法设置权限 -

GWAuthPermission:
    Type: "AWS::Lambda::Permission"
    Properties:
      Action: lambda:InvokeFunction
      FunctionName: !GetAtt AuthTest.Arn
      Principal: "apigateway.amazonaws.com"
      SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiGatewayRestApi}/authorizers/${AuthTest}"

ApiGatewayRestApi - 网关的逻辑 ID
AuthTest - 自定义身份验证 lambda 函数的逻辑 ID

【问题讨论】:

  • 试试Serverless,比CloudFormation简单,内部生成cloudformation模板。 serverless.com/framework/docs/providers/aws/events/apigateway/…
  • @Gangaraju 实际上,由于多个供应商和不同的开发人员偏好,有些人更喜欢 SAM,有些人更喜欢无服务器,所以 Cloidformation 被决定为基础设施设置的标准。
  • 您仍然可以尝试无服务器来生成 CloudFormation 模板并将生成的代码复制到您的项目中。

标签: amazon-web-services aws-lambda amazon-cloudformation aws-api-gateway


【解决方案1】:

我能够通过以下方式解决它 -

添加了AWS::ApiGateway::Authorizer资源,
并将其转介给AWS::Lambda::Permission

代码 -

GWAuth:
    Type: AWS::ApiGateway::Authorizer
    Properties: 
      AuthorizerUri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${AuthLambda.Arn}/invocations"
      RestApiId: !Ref ApiGatewayRestApi
      Type: "REQUEST"
      IdentitySource: method.request.header.authorization
      Name: custom_auth

  GWAuthPermission:
    Type: "AWS::Lambda::Permission"
    Properties:
      Action: lambda:InvokeFunction
      FunctionName: !GetAtt AuthLambda.Arn
      Principal: "apigateway.amazonaws.com"
      SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiGatewayRestApi}/authorizers/${GWAuth}"

【讨论】:

    猜你喜欢
    • 2020-03-17
    • 1970-01-01
    • 2020-09-21
    • 2018-10-11
    • 2018-08-03
    • 1970-01-01
    • 2023-03-15
    • 2017-08-20
    • 1970-01-01
    相关资源
    最近更新 更多