aws-cdk

Is there a way to configure a Cognito domain branding version using CDK?


enter image description here

I haven't found any documentation on a way to set the Branding version from CDK.

Example code:

    const userPool = new cognito.UserPool(this, userPoolName, {
      userPoolName,
      deletionProtection: true,
      deviceTracking: {
        challengeRequiredOnNewDevice: true,
        deviceOnlyRememberedOnUserPrompt: true,
      },
      signInAliases: {
        email: true,
        phone: true,
      },
    });

    // Adds domain
    userPool.addDomain(`${appName}-userpool-domain-${env}`, {
      cognitoDomain: {
        domainPrefix: `${appName}-${env}`,
      },
    });

Solution

  • The solution I'm currently going with is to use the AwsCustomerResource construct to call AWS SDK to update the user pool domain. The AWS SDK documentation for UpdateUserPoolDomainCommand is found here.

        new AwsCustomResource(
          this,
          `${appName}-update-userpool-domain-acr-${env}`,
          {
            installLatestAwsSdk: true,
            functionName: `${appName}-update-userpool-domain-fn-${env}`,
            onCreate: {
              service: "@aws-sdk/client-cognito-identity-provider",
              action: "UpdateUserPoolDomainCommand",
              parameters: {
                Domain: `${appName}-${env}`,
                ManagedLoginVersion: 2,
                UserPoolId: userPool.userPoolId,
              },
              physicalResourceId: {},
            },
            policy: AwsCustomResourcePolicy.fromSdkCalls({ resources: ["*"] }),
          }
        );