Cognito user pool authorizer With Serverless Framework

后端 未结 3 1172
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 00:42

I need to authorize my API end point using aws cognito userpool. I can do it manually, but I need to automate the authorization part with the serverless framework.

3条回答
  •  旧巷少年郎
    2020-12-31 01:28

    If you want to set the authorizer to a Cognito User Pool you have declared in your resources you must use CloudFormation to create the authorizer as well.

    functions:
      functionName:
        # ...
        events:
          - http:
              # ...
              authorizer: 
                 type: COGNITO_USER_POOLS
                 authorizerId: 
                   Ref: ApiGatewayAuthorizer
    
    resources:
      Resources:
        ApiGatewayAuthorizer: 
          Type: AWS::ApiGateway::Authorizer
          Properties: 
            Name: CognitoUserPool
            Type: COGNITO_USER_POOLS
            IdentitySource: method.request.header.Authorization
            RestApiId: 
              Ref: ApiGatewayRestApi
            ProviderARNs: 
              - Fn::GetAtt:
                  - UserPool
                  - Arn
    
        UserPool:
          Type: AWS::Cognito::UserPool
    

提交回复
热议问题