Using your own domain for the hosted UI
After you set up an app client, you can configure your user pool with a custom domain for the Amazon Cognito hosted UI and authorization server endpoints. With a custom domain, users can sign in to your application using your own web address instead the default Amazon Cognito domain. Custom domains improve user trust in your application with a familiar domain name, especially when the root domain matches the domain that hosts your application. Custom domains can also comply with organizational security requirements.
A custom domain has some prerequisites, including a user pool, an app client, and a web domain that you own. Custom domains also require an SSL certificate for the custom domain, managed with AWS Certificate Manager (ACM) in US East (N. Virginia). Amazon Cognito creates a Amazon CloudFront distribution, secured in transit with your ACM certificate, that must be the DNS alias target of your custom domain name.
After these elements are ready, you can add the custom domain to your user pool through the Amazon Cognito console or API. This involves specifying the domain name and SSL certificate, and then updating your DNS configuration with the provided alias target. After making these changes, you can verify that the sign-in page is accessible at your custom domain.
Adding a custom domain to a user pool
To add a custom domain to your user pool, you specify the domain name in the Amazon Cognito console, and you provide a certificate you manage with AWS Certificate Manager (ACM). After you add your domain, Amazon Cognito provides an alias target, which you add to your DNS configuration.
Prerequisites
Before you begin, you need:
-
A user pool with an app client. For more information, see Getting started with user pools.
-
A web domain that you own. Its parent domain must have a valid DNS A record. You can assign any value to this record. The parent may be the root of the domain, or a child domain that is one step up in the domain hierarchy. For example, if your custom domain is auth.xyz.example.com, Amazon Cognito must be able to resolve xyz.example.com to an IP address. To prevent accidental impact on customer infrastructure, Amazon Cognito doesn't support the use of top-level domains (TLDs) for custom domains. For more information see Domain Names
. -
The ability to create a subdomain for your custom domain. We recommend using auth as the subdomain. For example:
auth.example.com
.Note
You might need to obtain a new certificate for your custom domain's subdomain if you don't have a wildcard certificate
. -
A Secure Sockets Layer (SSL) certificate managed by ACM.
Note
You must change the AWS region to US East (N. Virginia) in the ACM console before you request or import a certificate.
-
An application that permits your user pool authorization server to add cookies to user sessions. Amazon Cognito sets several required cookies for the hosted UI. These include
cognito
,cognito-fl
, andXSRF-TOKEN
. Although each individual cookie conforms to browser size limits, changes to your user pool configuration might cause hosted UI cookies to grow in size. An intermediate service like an Application Load Balancer (ALB) in front of your custom domain might enforce a maximum header size or total cookie size. If your application also sets its own cookies, your users' sessions might exceed these limits. We recommend that, to avoid size limit conflicts, your application not set cookies on the hosted UI subdomain. -
Permission to update Amazon CloudFront distributions. You can do so by attaching the following IAM policy statement to a user in your AWS account:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowCloudFrontUpdateDistribution", "Effect": "Allow", "Action": [ "cloudfront:updateDistribution" ], "Resource": [ "*" ] } ] }
For more information about authorizing actions in CloudFront, see Using Identity-Based Policies (IAM Policies) for CloudFront.
Amazon Cognito initially uses your IAM permissions to configure the CloudFront distribution, but the distribution is managed by AWS. You can't change the configuration of the CloudFront distribution that Amazon Cognito associated with your user pool. For example, you can't update the supported TLS versions in the security policy.
Step 1: Enter your custom domain name
You can add your domain to your user pool by using the Amazon Cognito console or API.
Step 2: Add an alias target and subdomain
In this step, you set up an alias through your Domain Name Server (DNS) service provider that points back to the alias target from the previous step. If you are using Amazon Route 53 for DNS address resolution, choose the section To add an alias target and subdomain using Route 53.
-
If you aren't using Route 53 for DNS address resolution, then you must use your DNS service provider's configuration tools to add the alias target from the previous step to your domain's DNS record. Your DNS provider will also need to set up the subdomain for your custom domain.
-
Sign in to the Route 53 console
. If prompted, enter your AWS credentials. -
If you don't have a public hosted zone in Route 53, create one with a root that is a parent of your custom domain. For more information, see Creating a public hosted zone in the Amazon Route 53 Developer Guide.
-
Choose Create Hosted Zone.
-
Enter the parent domain, for example
auth.example.com
, of your custom domain, for examplemyapp.auth.example.com
, from the Domain Name list. -
Enter a Description for your hosted zone.
-
Choose a hosted zone Type of Public hosted zone to allow public clients to resolve your custom domain. Choosing Private hosted zone is not supported.
-
Apply Tags as desired.
-
Choose Create hosted zone.
Note
You can also create a new hosted zone for your custom domain with a delegation set in the parent hosted zone that directs queries to the subdomain hosted zone. Otherwise, create an A record. This method offers more flexibility and security with your hosted zones.For more information, see Creating a subdomain for a domain hosted through Amazon Route 53
.
-
-
On the Hosted Zones page, choose the name of your hosted zone.
-
Add a DNS record for the parent domain of your custom domain, if you don’t already have one. Create a DNS record for the parent domain with the following properties:
-
Record name: Leave blank.
-
Record type:
A
. -
Alias: Don't enable.
-
Value: Enter a target of your choosing. This record must resolve to something, but the value of the record doesn't matter to Amazon Cognito.
-
TTL: Set to your preferred TTL or leave as default.
-
Routing policy: Choose Simple routing.
-
-
Choose Create records. The following is an example record for the domain
example.com
:example.com.
60 IN A198.51.100.1
Note
Amazon Cognito verifies that there is a DNS record for the parent domain of your custom domain to protect against accidental hijacking of production domains. If you do not have a DNS record for the parent domain, Amazon Cognito will return an error when you attempt to set the custom domain. A Start of Authority (SOA) record isn't a sufficient DNS record for the purposes of parent-domain verification.
-
Add another DNS record for your custom domain with the following properties:
-
Record name: Your custom domain prefix, for example
auth
to create a record forauth.example.com
. -
Record type:
A
. -
Alias: Enable.
-
Route traffic to: Choose Alias to Cloudfront distribution. Enter the Alias target you recorded earlier, for example
123example.cloudfront.net
. -
Routing policy: Choose Simple routing.
-
-
Choose Create records.
Note
Your new records can take around 60 seconds to propagate to all Route 53 DNS servers. You can use the Route 53 GetChange API method to verify that your changes have propagated.
Step 3: Verify your sign-in page
-
Verify that the sign-in page is available from your custom domain.
Sign in with your custom domain and subdomain by entering this address into your browser. This is an example URL of a custom domain
example.com
with the subdomainauth
:https://
myapp
.auth
.example.com
/login?response_type=code&client_id=<your_app_client_id>
&redirect_uri=<your_callback_url>
Changing the SSL certificate for your custom domain
When necessary, you can use Amazon Cognito to change the certificate that you applied to your custom domain.
Usually, this is unnecessary following routine certificate renewal with ACM. When you renew your existing certificate in ACM, the ARN for your certificate remains the same, and your custom domain uses the new certificate automatically.
However, if you replace your existing certificate with a new one, ACM gives the new certificate a new ARN. To apply the new certificate to your custom domain, you must provide this ARN to Amazon Cognito.
After you provide your new certificate, Amazon Cognito requires up to 1 hour to distribute it to your custom domain.
Before you begin
Before you can change your certificate in Amazon Cognito, you must add your certificate to ACM. For more information, see Getting Started in the AWS Certificate Manager User Guide.
When you add your certificate to ACM, you must choose US East (N. Virginia) as the AWS Region.
You can change your certificate by using the Amazon Cognito console or API.