英文:
AWS CDK (Java): Add a Group to a UserPool
问题
AWS CDK(Java)尝试将一个组添加到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());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论