Ashish Karpe
Ashish Karpe

Reputation: 5804

AWS CDK TypeScript issue [type='CNAME'] but it already exists

I am new to AWS CDK TypeScript.

My issue is: [Tried to create resource record set [name='xxxxx', type='CNAME'] but it already exists]"}

Using AWS CDK TypeScript I am creating stacks in eu-west1 and eu-central regions. So is there any mechanism to check if cname is not created then only create?

My code current code:

   const cName = new route53.CnameRecord(this, "cName", {
            zone: route53.HostedZone.fromLookup(this, "lowerHostedZone3", {
                domainName: topDomain,
            }),
  
            recordName: topFQDN,
            domainName: lowerFQDN

        }); 

Upvotes: 3

Views: 2476

Answers (2)

I had this issue and would like to avoid others spending 24 hours working on it. My answer is for the generic problem: "name" already exists.

Get rid of them. Get rid of all instances of names that are optional to the classes being invoked. Let them generate it for you. Don't use try blocks, don't try to retrieve them if it exists (at the time of writing, such an approach did not work).

Don't delete the stack every time to solve this issue, simply do not use names.

Resources

Upvotes: 0

LRutten
LRutten

Reputation: 1902

Deploying the stack in multiple regions will probably create the same entry twice (one for eu-west-1 and one for eu-central-1). Since route53 is a global service, this could be the cause of the error you see.

Instead of doing a lookup you can simply choose to make 1 region leading for DNS, or include the region name in the DNS entries (my-service.eu-west-1.my-domain.com), and then front it with something like cloudfront or global accelerator to do global routing to the nearest region.

Upvotes: 1

Related Questions