Amazon web services AWS:在多个无服务器应用程序中重新使用amazon Cognito用户池

Amazon web services AWS:在多个无服务器应用程序中重新使用amazon Cognito用户池,amazon-web-services,aws-lambda,amazon-cloudformation,amazon-cognito,serverless-framework,Amazon Web Services,Aws Lambda,Amazon Cloudformation,Amazon Cognito,Serverless Framework,我将我的无服务器项目划分为多个项目,以避免模板错误资源>200。现在我面临着另一个错误 我已经使用AWS cognito实现了身份验证和授权,它在一个无服务器应用程序中很适合lambda函数。我试图在另一个无服务器项目中重用同一个Cognoto用户池来授权API。然而,每个无服务器项目都会在Cognito中使用相同的名称再次创建UserPool。如何避免这个问题 下面是我的serverless.yml和虚拟响应在lambda函数中的样子 CognitoUserPool: Type: "AWS

我将我的无服务器项目划分为多个项目,以避免模板错误资源>200。现在我面临着另一个错误

我已经使用AWS cognito实现了身份验证和授权,它在一个无服务器应用程序中很适合lambda函数。我试图在另一个无服务器项目中重用同一个Cognoto用户池来授权API。然而,每个无服务器项目都会在Cognito中使用相同的名称再次创建UserPool。如何避免这个问题

下面是我的serverless.yml和虚拟响应在lambda函数中的样子

CognitoUserPool:
  Type: "AWS::Cognito::UserPool"
  Properties:
    MfaConfiguration: OFF
    UserPoolName: userpool-impl
    #RequiredAttributes:
    #  - email
    UsernameAttributes:
      - email
    Policies:
      PasswordPolicy:
        MinimumLength: 8
        RequireLowercase: True
        RequireNumbers: True
        RequireSymbols: True
        RequireUppercase: True


CognitoUserPoolClient:
  Type: "AWS::Cognito::UserPoolClient"
  Properties:
    ClientName: client-impl
    GenerateSecret: False
    UserPoolId:
      Ref: CognitoUserPool

ApiGatewayAuthorizer:
  DependsOn:
    - ApiGatewayRestApi
  Type: AWS::ApiGateway::Authorizer
  Properties:
    Name: cognito-authorizer
    IdentitySource: method.request.header.Authorization
    RestApiId:
      Ref: ApiGatewayRestApi
    Type: COGNITO_USER_POOLS
    ProviderARNs:
      - Fn::GetAtt: [CognitoUserPool, Arn]
Lamdba函数:

response = {
"statusCode": 200,
'headers': {
             "Access-Control-Allow-Origin": "http://localhost:3000",
             "Access-Control-Allow-Credentials": True
        },

"body": "Dummy Response"

}

不要在新的无服务器项目中创建用户池;它已经存在了。对于您的API网关授权人,在ProviderARNs中放置您想要使用的其他项目的ARN。我们对我们的无服务器项目也这么做。。。工作正常。您可以使用跨堆栈引用()。您可以只引用其他项目中的现有用户池。@hephalump您可以帮助在无服务器yml文件中进行配置吗?如何进行交叉引用?不要在新的无服务器项目中创建用户池;它已经存在了。对于您的API网关授权人,在ProviderARNs中放置您想要使用的其他项目的ARN。我们对我们的无服务器项目也这么做。。。工作正常。您可以使用跨堆栈引用()。您可以只引用其他项目中的现有用户池。@hephalump您可以帮助配置无服务器yml文件吗?如何进行交叉引用?