AWS + 无服务器 - 如何获取 Cognito 用户池生成的密钥

AWS + Serverless - how to get at the secret key generated by cognito user pool

我一直在关注 https://serverless-stack.com/chapters/configure-cognito-user-pool-in-serverless.html

上的无服务器教程

我有以下无服务器 yaml 代码片段

Resources:
  CognitoUserPool:
    Type: AWS::Cognito::UserPool
    Properties:
      # Generate a name based on the stage
      UserPoolName: ${self:custom.stage}-moochless-user-pool
      # Set email as an alias
      UsernameAttributes:
      - email
      AutoVerifiedAttributes:
      - email

  CognitoUserPoolClient:
    Type: AWS::Cognito::UserPoolClient
    Properties:
      # Generate an app client name based on the stage
      ClientName: ${self:custom.stage}-user-pool-client
      UserPoolId:
        Ref: CognitoUserPool
      ExplicitAuthFlows:
      - ADMIN_NO_SRP_AUTH
      # >>>>> HOW DO I GET THIS VALUE IN OUTPUT <<<<<
      GenerateSecret: true

# Print out the Id of the User Pool that is created
Outputs:
  UserPoolId:
    Value:
      Ref: CognitoUserPool

  UserPoolClientId:
    Value:
      Ref: CognitoUserPoolClient
  #UserPoolSecret:
  #   WHAT GOES HERE?

我正在将所有其他配置变量导出到 json 文件(供移动应用程序使用,因此我需要密钥)。

如何让生成的密钥出现在我的输出列表中?

检索密钥的理想方法是在您的 cloudformation 模板中使用 "CognitoUserPoolClient.ClientSecret"。

UserPoolClientIdSecret:
  Value:    
   !GetAtt CognitoUserPoolClient.ClientSecret

但如说明的那样不受支持here and gives message as shown in the image: 您可以 运行 在 CLI 命令下检索密钥作为变通方法:

aws cognito-idp describe-user-pool-client --user-pool-id "us-west-XXXXXX"  --region us-west-2 --client-id "XXXXXXXXXXXXX" --query 'UserPoolClient.ClientSecret' --output text