UserPoolDomainProps

class aws_cdk.aws_cognito.UserPoolDomainProps(*, cognito_domain=None, custom_domain=None, user_pool)

Bases: UserPoolDomainOptions

Props for UserPoolDomain construct.

Parameters:
  • cognito_domain (Union[CognitoDomainOptions, Dict[str, Any], None]) – Associate a cognito prefix domain with your user pool Either customDomain or cognitoDomain must be specified. Default: - not set if customDomain is specified, otherwise, throws an error.

  • custom_domain (Union[CustomDomainOptions, Dict[str, Any], None]) – Associate a custom domain with your user pool Either customDomain or cognitoDomain must be specified. Default: - not set if cognitoDomain is specified, otherwise, throws an error.

  • user_pool (IUserPool) – The user pool to which this domain should be associated.

ExampleMetadata:

infused

Example:

from aws_cdk import aws_certificatemanager as acm

# vpc: ec2.Vpc
# certificate: acm.Certificate


lb = elbv2.ApplicationLoadBalancer(self, "LB",
    vpc=vpc,
    internet_facing=True
)

user_pool = cognito.UserPool(self, "UserPool")
user_pool_client = cognito.UserPoolClient(self, "Client",
    user_pool=user_pool,

    # Required minimal configuration for use with an ELB
    generate_secret=True,
    auth_flows=cognito.AuthFlow(
        user_password=True
    ),
    o_auth=cognito.OAuthSettings(
        flows=cognito.OAuthFlows(
            authorization_code_grant=True
        ),
        scopes=[cognito.OAuthScope.EMAIL],
        callback_urls=[f"https://{lb.loadBalancerDnsName}/oauth2/idpresponse"
        ]
    )
)
cfn_client = user_pool_client.node.default_child
cfn_client.add_property_override("RefreshTokenValidity", 1)
cfn_client.add_property_override("SupportedIdentityProviders", ["COGNITO"])

user_pool_domain = cognito.UserPoolDomain(self, "Domain",
    user_pool=user_pool,
    cognito_domain=cognito.CognitoDomainOptions(
        domain_prefix="test-cdk-prefix"
    )
)

lb.add_listener("Listener",
    port=443,
    certificates=[certificate],
    default_action=actions.AuthenticateCognitoAction(
        user_pool=user_pool,
        user_pool_client=user_pool_client,
        user_pool_domain=user_pool_domain,
        next=elbv2.ListenerAction.fixed_response(200,
            content_type="text/plain",
            message_body="Authenticated"
        )
    )
)

CfnOutput(self, "DNS",
    value=lb.load_balancer_dns_name
)

Attributes

cognito_domain

Associate a cognito prefix domain with your user pool Either customDomain or cognitoDomain must be specified.

Default:
  • not set if customDomain is specified, otherwise, throws an error.

See:

https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-assign-domain-prefix.html

custom_domain

Associate a custom domain with your user pool Either customDomain or cognitoDomain must be specified.

Default:
  • not set if cognitoDomain is specified, otherwise, throws an error.

See:

https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-add-custom-domain.html

user_pool

The user pool to which this domain should be associated.