从 serverless.yml 创建 AWS Cognito 用户池

Creating AWS Cognito User Pool from serverless.yml

我正在尝试使用 AWS Cognito 用户池进行用户身份验证,但我似乎无法弄清楚如何从 serverless.yml 文件中创建用户池。我知道要创建其他资源,您可以执行以下操作:

resources:
  Resources:
    Table:
      Type: "AWS::DynamoDB::Table"  # Change this to "AWS::Cognito::UserPool"?
      DeletionPolicy: Retain
      Properties:                   # Change the properties here, but to what?
        AttributeDefinitions:
          -
            AttributeName: id
            AttributeType: S
        KeySchema:
          -
            AttributeName: id
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: arn:aws:dynamodb:us-west-1:*:table/tablename

我假设我只需要将类型更改为 "AWS:Cognito::UserPool" 并更改属性。但是,我不知道该改成什么。

一个简单的搜索返回了这个:https://serverless-stack.com/chapters/configure-cognito-user-pool-in-serverless.html

对于那些寻找基本示例的人,请参阅@ionut 的回答。 AWS::Cognito::UserPool 的所有配置都可以在 here. As for the AWS::Cognito::UserPoolClient, it can be found here.

中找到

非常简单明了。

您需要做的就是创建一些资源,然后将它们从您的模板文件中导出。

我通常做的是首先创建一个资源文件(例如,Cognito-user-pool.yml)并在其中添加必要的资源和导出声明。之后,我将从我的 serverless.yml 文件中调用资源 ( ${ file(./cognito-user-pool.yml)}

在您的用户池资源声明中,您需要为

添加定义
  1. CognitoUserPool
  2. 应用客户端
  3. 身份池
  4. 必要的角色附件声明
  5. 使用必要的策略定义角色。
  6. 导出前三个资源:如果您想将 Cognitoo 用户池与您的前端连接(可能使用 AWS-amplify)
  7. 部署堆栈

在这个博客中post我已经详细解释了这些步骤,还添加了一个 YouTube 视频来解释每个步骤。

博客 Link:https://www.codegigs.app/how-to-cognito-user-pool-using-serverless/ 视频 Link:https://youtu.be/bv_imx8gfLU