【问题标题】:Adding AWS Cognito User Pool role using CDK使用 CDK 添加 AWS Cognito 用户池角色
【发布时间】:2020-09-19 15:32:09
【问题描述】:

我已将https://github.com/aws-samples/amazon-elasticsearch-service-with-cognito 部署到我的堆栈中,并尝试按照https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/fgac.html#fgac-walkthrough-iam 添加一个master

所以我在下面添加了https://github.com/aws-samples/amazon-elasticsearch-service-with-cognito/blob/master/lib/search-stack.ts#L50

diff --git a/lib/search-stack.ts b/lib/search-stack.ts
index 85de0c0..2493c92 100644
--- a/lib/search-stack.ts
+++ b/lib/search-stack.ts
@@ -3,7 +3,7 @@

 import { Fn, Stack, Construct, StackProps, CfnParameter, CfnOutput } from '@aws-cdk/core';
 import { CfnDomain } from '@aws-cdk/aws-elasticsearch';
-import { UserPoolAttribute, CfnUserPoolDomain, CfnIdentityPool, CfnIdentityPoolRoleAttachment, CfnUserPool } from '@aws-cdk/aws-cognito';
+import { UserPoolAttribute, CfnUserPoolDomain, CfnIdentityPool, CfnIdentityPoolRoleAttachment, CfnUserPool, CfnUserPoolGroup } from '@aws-cdk/aws-cognito';
 import { Role, ManagedPolicy, ServicePrincipal, FederatedPrincipal } from '@aws-cdk/aws-iam';
 import { CustomResource } from '@aws-cdk/aws-cloudformation';

@@ -55,6 +55,19 @@ export class SearchStack extends Stack {
       }, "sts:AssumeRoleWithWebIdentity")
     });

+    // create two groups, one for admins one for users
+
+    new CfnUserPoolGroup(this, "AdminsGroup", {
+      groupName: "master-user-group",
+      userPoolId: idPool.ref,
+
+    });
+
+    new CfnUserPoolGroup(this, "UsersGroup", {
+      groupName: "limited-user-group",
+      userPoolId: idPool.ref,
+    });
+
     const esRole = new Role(this, "esRole", {
       assumedBy: new ServicePrincipal('es.amazonaws.com'),
       managedPolicies: [ManagedPolicy.fromAwsManagedPolicyName("AmazonESCognitoAccess")]
~

但是在重新部署角色后没有被创建!

非常感谢任何建议。

【问题讨论】:

    标签: amazon-web-services aws-cdk aws-elasticsearch


    【解决方案1】:

    好的,我需要使用:

    
        new CfnUserPoolGroup(this, "AdminsGroup", {
          groupName: "master-user-group",
          userPoolId: userPool.ref
        });
    
        new CfnUserPoolGroup(this, "UsersGroup", {
          groupName: "limited-user-group",
          userPoolId: userPool.ref
        });
    
    

    而不是idPool.ref

    【讨论】:

    • 你打败了我。昨天我看到了,但我被跟踪了,完全错过了回答。谢天谢地,你把一切都搞定了!!
    【解决方案2】:

    从 AWS CDK v1.91.0 开始,使用 userPoolId 而不是 ref

    import * as cognito from '@aws-cdk/aws-cognito';
    
    //...
    
    const userPool = new cognito.UserPool(this, 'UserPool', {
      //...
    });
    
    new cognito.CfnUserPoolGroup(this, "ManagerGroup", {
      groupName: "manager",
      userPoolId: userPool.userPoolId
    });
        
    

    【讨论】:

      【解决方案3】:

      从 1.1.1 版开始,amazon-elasticsearch-service-with-cognito code 包括用于细粒度访问控制的配置,包括名为“es-admins”的 Amazon Cognito 组和所需的角色解析。

      【讨论】:

        猜你喜欢
        • 2020-09-01
        • 2019-08-15
        • 2018-09-08
        • 2019-10-06
        • 2018-03-16
        • 1970-01-01
        • 2018-07-17
        • 2019-11-29
        • 2021-08-11
        相关资源
        最近更新 更多