代码之家  ›  专栏  ›  技术社区  ›  Hamed Minaee

无法通过cloudformation设置cognoto userpool client的属性

  •  3
  • Hamed Minaee  · 技术社区  · 6 年前

    我试着通过云层运行congnito,一切正常,但cognito中有如下部分:

    enter image description here

    如您所见,有一节“启用身份提供程序” 在cloudformation中,我找不到可以将其设置为cognito用户池的位置!

    我试过这个属性,但它说不支持。

    SupportedIdentityProviders
    

    以下是我的用户池客户端代码:

      UserPoolClient:
    Type: "AWS::Cognito::UserPoolClient"
    Properties:
      ClientName: !Sub ${project}-client
      ExplicitAuthFlows:
       - ADMIN_NO_SRP_AUTH
       - USER_PASSWORD_AUTH
      GenerateSecret: false
      UserPoolId: !Ref UserPool
      RefreshTokenValidity: 30
    

    这是我的用户池:

      UserPool:
    Type: "AWS::Cognito::UserPool"
    Properties:
      UserPoolName: !Sub ${project}-user-pool-test
      AutoVerifiedAttributes:
        - email
      UsernameAttributes:
        - email
      MfaConfiguration: "OFF"
      LambdaConfig:
        CustomMessage:
          Fn::ImportValue: !Sub ${project}-${EnvironmentApp}-lambda-cognito-custom-message-post
      Policies:
        PasswordPolicy:
          MinimumLength: !Ref MinimumLength
          RequireLowercase: !Ref RequireLowercase
          RequireNumbers: !Ref RequireNumbers
          RequireSymbols: !Ref RequireSymbols
          RequireUppercase: !Ref RequireUppercase
      Schema:
        -
            AttributeDataType: String
            DeveloperOnlyAttribute: false
            Mutable: true
            Name: !Sub ${project}-stg
            Required: false
        -
            AttributeDataType: String
            DeveloperOnlyAttribute: false
            Mutable: true
            Name: !Sub zuora-stg
            Required: false
        -
            AttributeDataType: String
            DeveloperOnlyAttribute: false
            Mutable: true
            Name: !Sub salesforce-stg
            Required: false
    

    它是否支持云的形成?我很感激你的帮助?

    3 回复  |  直到 6 年前
        1
  •  2
  •   toske    6 年前

    正如另一个答案所暗示的那样,这还不能在云层形成中实现。然而,asr-answer建议可以通过cloudformation自定义资源来实现。

    我的雇主已经公开了它收集的定制资源,包括 认知用户库 认知域名 (在云层中也不受支持)自定义资源源代码 can be found on github

    下面是设置此设置的手动说明-您也可以通过在CloudFormation中放置自定义资源backing Lambda来进一步实现自动化。

    下面的所有命令都是针对Mac的您可能需要修改其他 平台

    一。为lambda创建iam角色

    aws iam create-role --role-name LambdaRoleCognito --assume-role-policy-document '{
          "Version": "2012-10-17",
          "Statement": [
          {
              "Effect": "Allow",
              "Principal": {
                  "Service": "lambda.amazonaws.com"
              },
              "Action": "sts:AssumeRole"
          }
      ]
      }'
    aws iam attach-role-policy --role-name LambdaRoleCognito \
      --policy-arn  arn:aws:iam::aws:policy/CloudWatchLogsFullAccess
    
    aws iam attach-role-policy --role-name LambdaRoleCognito \
      --policy-arn  arn:aws:iam::aws:policy/AmazonCognitoPowerUser
    

    2下载lambda源代码,上传到本地bucket,并创建lambda

    wget https://github.com/base2Services/cloudformation-custom-resources-nodejs/releases/download/1.0.0/ccr-nodejs-1.0.0.zip
    account_id=$(aws sts get-caller-identity --query Account --output text)
    aws s3 mb s3://${account_id}.cfncustomres.source
    aws s3 cp ccr-nodejs-1.0.0.zip s3://${account_id}.cfncustomres.source/ccr-nodejs-1.0.0.zip
    
    aws lambda create-function --function-name CfnCrCognitUPC --runtime nodejs6.10 \
        --role arn:aws:iam::${account_id}:role/LambdaRoleCognito  \
        --timeout 30 \
        --memory-size 512 \
        --code S3Bucket=${account_id}.cfncustomres.source,S3Key=ccr-nodejs-1.0.0.zip \
        --handler cognito-user-pool-client/index.handler
    

    三。 可选的 通过调用test payload测试lambda

    aws lambda invoke --function-name CfnCrCognitUPC --payload '{
      "StackId": "arn:aws:cloudformation:us-west-2:EXAMPLE/stack-name/guid",
      "ResponseURL": "http://pre-signed-S3-url-for-response",
      "ResourceProperties": {
        "ClientName": "MyCCRCreatedUP",
        "SupportedIdentityProviders": [
          "COGNITO"
        ],
        "UserPoolId":"!! REPLACE WITH YOUR USER POOL ID !!"
      },
      "RequestType": "Create",
      "ResourceType": "Custom::TestResource",
      "RequestId": "unique id for this create request",
      "LogicalResourceId": "MyTestResource"
    }' --log-type Tail --invocation-type RequestResponse output.txt --query LogResult --output text | base64 -D
    

    四。在cloudformation模板中创建自定义资源

    对于所有支持的属性的列表签出 custom resource JSON schema

    Resources:
      MyPoolApplication:
        Type: Custom::CognitoUserPool
        Properties:
          ServiceToken: arn:aws:lambda:<<REPLACE_WITH_YOUR_REGION>>:<<REPLACE_WITH_YOUR_ACCOUNT_ID>>:function:CfnCrCognitUPC
          ClientName: ApplicationClientNameHere
          UserPoolId: 
            Ref: UserPool
          SupportedIdentityProviders:
            - COGNITO
          .... other support properties .... 
    
        2
  •  1
  •   asr9    6 年前

    上个月我遇到了同样的问题。cfn中尚不支持此属性。所以我最终使用cfn自定义资源创建池客户机。更多关于这里 CFN Custom Resource . 本质上,我让cfn调用lambda函数来创建用户池客户端(sdk中支持所有属性)。

        3
  •  1
  •   Ravenscar    6 年前

    正如ASR所说,这似乎还不支持云计算。

    我们最终尝试了Terraform——它确实支持它。

    resource "aws_cognito_user_pool_client" "my_client" {
      ...
      supported_identity_providers = ["COGNITO"]
    }
    

    我们现在已经将一切转换为使用terraform,因为它比Cloudformation更容易理解、读取和写入数量级。

    我知道这可能不是你想要的答案,但我希望能有所帮助。