AWS CDK(Java):将用户组添加到用户池

huangapple go评论84阅读模式
英文:

AWS CDK (Java): Add a Group to a UserPool

问题

AWS CDKJava尝试将一个组添加到UserPool时失败错误信息为:“Error: 在Stack [CdkStackTest]中已经存在一个名为 'CdkStackTest' 的Construct”。我认为 'scope' 参数正在将CfnUserPoolGroup创建为另一个具有相同名称的构造我应该如何正确地创建一个组并将其与UserPool关联

public class CdkStackMain extends Stack {

    public CdkStackMain(final Construct scope, final String id, final StackProps props, StackMode stackMode) {
        super(scope, id, props);

        // 在这里成功创建了userPool

        CfnUserPoolGroup.Builder
                .create(scope, id)
                .groupName("admin")
                .userPoolId(userPool.getUserPoolId())
                .build();
    }
}
英文:

AWS CDK (Java) Attempting to add a Group to UserPool is failing with: "Error: There is already a Construct with name 'CdkStackTest' in Stack [CdkStackTest]". I believe the 'scope' param is creating the CfnUserPoolGroup as another construct with the same name. How do I (correctly) create a group and associate it with a UserPool?

public class CdkStackMain extends Stack {

	public CdkStackMain(final Construct scope, final String id, final StackProps props, StackMode stackMode) {
		super(scope, id, props);

        // userPool successfully created here

		CfnUserPoolGroup.Builder
				.create(scope, id)
				.groupName("admin")
				.userPoolId(userPool.getUserPoolId())
				.build();
	}
}

答案1

得分: 1

我发现如果我将''scope''替换为''this'',并将'id'更改为唯一标识符,那么CfnUserPoolGroup就可以成功地与UserPool关联起来。我还了解到最佳实践是指定该组取决于UserPool的存在。

CfnUserPoolGroup.Builder
	.create(this, "adminGroup")
	.groupName("admin")
	.userPoolId(userPool.getUserPoolId())
	.build()
	.addDependsOn((CfnResource)userPool.getNode().getDefaultChild());
英文:

I found that if I replace 'scope' with 'this' and changed 'id' to a unique identifier that the CfnUserPoolGroup could be successfully associated with the UserPool. I also learned that it is best practice to designate that the Group depends on UserPool existence.

CfnUserPoolGroup.Builder
	.create(this, "adminGroup")
	.groupName("admin")
	.userPoolId(userPool.getUserPoolId())
	.build()
	.addDependsOn((CfnResource)userPool.getNode().getDefaultChild());

huangapple
  • 本文由 发表于 2020年9月11日 10:12:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/63839899.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定