Update Existing Cognito User Pool Group via CDK

0

Hi,

I have a Cognito User Pool with a user group. This simple configuration deploys fine the first time. Any subsequent attempts to run cdk deploy with or without changes errors out with group already exists in stack error. I'm using Java for my CDK

Here's the code I'm using to create the user poll + group

  public void generateStack() {
    // Create User Pool
    UserPool userPool = Builder.create(scope, "some-id")
        .accountRecovery(AccountRecovery.EMAIL_ONLY)
        .autoVerify(AutoVerifiedAttrs.builder()
            .email(true)
            .phone(false)
            .build())
        .email(UserPoolEmail.withCognito(REPLY_TO_EMAIL))
        .enableSmsRole(false)
        .mfa(Mfa.OFF)
        .passwordPolicy(PasswordPolicy.builder()
            .minLength(8)
            .requireDigits(true)
            .requireLowercase(true)
            .requireUppercase(true)
            .tempPasswordValidity(Duration.days(TEMP_PWD_VALIDITY_IN_DAYS))
            .build())
        .removalPolicy(RemovalPolicy.RETAIN)
        .selfSignUpEnabled(true)
        .signInAliases(SignInAliases.builder()
            .email(true)
            .phone(false)
            .preferredUsername(false)
            .username(false)
            .build())
        .signInCaseSensitive(false)
        .standardAttributes(StandardAttributes.builder()
            .email(StandardAttribute.builder()
                .mutable(false)
                .required(true)
                .build())
            .givenName(StandardAttribute.builder()
                .mutable(true)
                .required(true)
                .build())
            .familyName(StandardAttribute.builder()
                .mutable(true)
                .required(true)
                .build())
            .phoneNumber(StandardAttribute.builder()
                .mutable(true)
                .required(true)
                .build())
            .build())
        .userPoolName("some-pool-name")
        .build();
    Role adminRole = Role.Builder.create(scope, "role-id")
        .roleName("admin-role")
        .assumedBy(new AccountRootPrincipal())
        .description("This is a full access admin role for Ops Team")
        .maxSessionDuration(Duration.hours(12))
        .managedPolicies(List.of(ManagedPolicy.fromAwsManagedPolicyName("AdministratorAccess")))
        .build();
    // Add admin group
    new CfnUserPoolGroup(scope, "admin-users", CfnUserPoolGroupProps.builder()
        .description("Admin group for the  Ops team")
        .groupName("admin-ops")
        .precedence(0)
        .roleArn(adminRole.getRoleArn())
        .userPoolId(userPool.getUserPoolId())
        .build());
  }

Is there a way to stop CDK from trying to create a group if it already exists in the stack?

Thanks Kunal

답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠