无服务器框架AWS ApiGateway v2授权者

时间:2020-05-06 20:08:31

标签: amazon-web-services aws-api-gateway amazon-cognito serverless-framework

我正在尝试基于此doc设置简单的授权者。还使用无服务器插件serverless-pseudo-parameters

我的用于授权人的无服务器配置:

provider:
...
  logs:
    httpApi: true
  httpApi:
    cors: true
    authorizers:
      simpleAuthorizer:
        identitySource: $request.header.Authorization
        issuerUrl:
          - Fn::Join:
              - '/'
              - - https://cognito-idp.#{AWS::Region}.amazonaws.com
                - "#{CognitoUserPool}"
        audience:
          - "#CognitoUserPoolClient"

我的简单lambda配置:

functions:
  ping:
    name: ${self:provider.stage}-ping
    handler: test.handler
    events:
      - httpApi:
          method: GET
          path: /test
          authorizer:
            name: simpleAuthorizer

我的用户池和用户池客户端配置:

resources:
  Resources:
    CognitoUserPool:
      Type: AWS::Cognito::UserPool
      Properties:
        UserPoolName: ${self:service}-${self:provider.stage}-user
        UsernameAttributes:
          - email
        Policies:
          PasswordPolicy:
            MinimumLength: 6
            RequireLowercase: False
            RequireNumbers: True
            RequireSymbols: False
            RequireUppercase: True
        Schema:
          - Name: email
            Required: false
            DeveloperOnlyAttribute: false
            Mutable: true
            AttributeDataType: String

    CognitoUserPoolClient:
      Type: AWS::Cognito::UserPoolClient
      Properties:
        ClientName: cognito-example-client
        GenerateSecret: False
        UserPoolId: "#{CognitoUserPool}"

用户池,用户池客户端,HTTP API,lambda已成功创建,但在API Gateway服务的AWS控制台上看不到授权者。

1 个答案:

答案 0 :(得分:0)

因此,该问题具有简单的解决方案:只需更新无服务器(我使用了1.63.0,这给了我这个问题)。