How can I resolve the "CNAMEAlreadyExists" error when I create an edge-optimized custom domain name for my API Gateway API?
I get an "CNAMEAlreadyExists" error when I try to create an edge-optimized custom domain name for my Amazon API Gateway API. How can I resolve this?
"I get an "CNAMEAlreadyExists" error when I try to create an edge-optimized custom domain name for my Amazon API Gateway API. How can I resolve this?Short descriptionThe "CNAMEAlreadyExists" error occurs if:The CNAME record type for your custom domain name already exists and points to an Amazon CloudFront distribution.There is a CloudFront distribution configured with an alternate domain name or CNAME that matches your custom domain name.Note: It's not uncommon to receive "Too Many Requests" errors when you make several custom domain name updates in a short timeframe. These errors occur because of low quota for the CreateDomainName API (one request every 30 seconds per account). For more information, see API Gateway quotas for creating, deploying and managing an API.Important: You can't use the same CNAME record for more than one CloudFront distribution. Using the same CNAME record returns the following error:One or more of the CNAMEs you provided are already associated with a different resource. (Service: AmazonCloudFront; Status Code: 409; Error Code: CNAMEAlreadyExists; Request ID: a123456b-c78d-90e1-23f4-gh5i67890jkl*To resolve these errors and create an edge-optimized custom domain name, you must first delete the existing CNAME record pointing to a CloudFront distribution.ResolutionConfirm if the custom domain name previously existed1.FSPTo confirm if the custom domain name previously existed, run a DNS lookup command on the domain name.On Linux, Unix, or macOS systems:dig abc.example.com +allOn Windows:nslookup abc.example.comNote: Replace abc.example.com with your domain name.2.FSPIf the custom domain name previously existed and its DNS record is still there, then use dig to get the CNAME record in the output:abc.example.comcom. 0        IN    CNAME    d27am47dhauq2.cloudfront.net.Important:You must delete this record before you can create the custom domain name.It's a best practice to modify DNS settings in a development or testing environment first. Manually modifying production DNS settings might cause downtime.If the output shows an A record (IPv4 address) instead of a CNAME record, then you must update the record. The updated record must point the custom domain name (A alias) to the CloudFront distribution.If a dig or nslookup is done on the domain name and the record is an A alias, check the CloudFront distribution. Make sure that the CloudFront distribution isn't configured with an alternate domain name. For more information, see Comparison of alias and CNAME records.Delete the CNAME record or update your CloudFront distributionDo one or both of the following depending on your configuration:Remove the CNAME record that points to your CloudFront distribution.Update your CloudFront distribution and remove the alternate domain name or CNAME record.If you have a third-party DNS service provider, then follow your providers process to delete the CNAME record that points to your CloudFront distribution.If you use Amazon Route 53, delete the record in Route 53 that points to CloudFront.After you have made the configuration changes, wait several minutes for the DNS changes to propagate. Then, retry creating the custom domain name.Note: If you receive "CNAMEAlreadyExists" errors, see How do I resolve the error CNAMEAlreadyExists when setting up a CNAME alias for my Amazon CloudFront distribution?Related informationHow can I set up a custom domain name for my API Gateway API?Building a multi-Region serverless application with Amazon API Gateway and AWS LambdaFollow"