aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.59k stars 3.89k forks source link

cdk destory isnt deleting route53 A record #4155

Closed harmohan-a closed 5 years ago

harmohan-a commented 5 years ago

i have a stack with s3 and route53 A record mapped to it.

cdk deploy works fine, creates a record in route53. However on cdk destroy it says its deleting the record but it doesnt ...

Screen Shot 2019-09-19 at 3 42 09 pm

If i go back to route53 in the console, the record is still there

Reproduction Steps

Error Log

Environment

Other


This is :bug: Bug Report

nmussy commented 5 years ago

This seems to be a CloudFormation limitation, according to the user guide:

You can't use AWS CloudFormation to update or delete records.

harmohan-a commented 5 years ago

😢

ok, thanks. but...but....but...it says its deleting it

0 | 5:35:18 AM | DELETE_IN_PROGRESS | AWS::Route53::RecordSet | ARecord (ARecordE7B57761)

nmussy commented 5 years ago

So I've tried to deploy and destroy the following stack, and it's working fine with v1.8.0. The record is created and then deleted:

const hostedZone = HostedZone.fromLookup(this, 'zone', {
    domainName: 'example.com',
});

new ARecord(this, 'A', {
    zone: hostedZone,
    target: RecordTarget.fromIpAddresses('8.8.8.8'),
    recordName: 'test',
});
> npx cdk deploy
TestStack: deploying...
TestStack: creating CloudFormation changeset...
 0/3 | 9:11:24 AM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata      | CDKMetadata
 0/3 | 9:11:24 AM | CREATE_IN_PROGRESS   | AWS::Route53::RecordSet | A (ACCC8ACD5)
 0/3 | 9:11:25 AM | CREATE_IN_PROGRESS   | AWS::Route53::RecordSet | A (ACCC8ACD5) Resource creation Initiated
 0/3 | 9:11:26 AM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata      | CDKMetadata Resource creation Initiated
 1/3 | 9:11:26 AM | CREATE_COMPLETE      | AWS::CDK::Metadata      | CDKMetadata
 2/3 | 9:11:57 AM | CREATE_COMPLETE      | AWS::Route53::RecordSet | A (ACCC8ACD5)
 3/3 | 9:11:59 AM | CREATE_COMPLETE      | AWS::CloudFormation::Stack | TestStack

 ✅  TestStack

> npx cdk destroy
Are you sure you want to delete: TestStack (y/n)? y
TestStack: destroying...
   1 | 9:12:17 AM | DELETE_COMPLETE      | AWS::CDK::Metadata      | CDKMetadata

 ✅  TestStack: destroyed

I assume the quote I pulled from the CloudFormation documentation is meant for records created outside the formation?

Either way, could you provide a minimal reproduction of your issue?

RomainMuller commented 5 years ago

It is also worth noting that what might have happened is the "even trace" displayed in the console might not show events that happened very close to the end of the deployment. Possibly, the cdk tool got a UPDATE_COMPLETE state on the stack itself before it could see the last few events from the tracking call... You might want to double-check in the Route53 console whether the record actually still exists, or whether the CloudFormation console actually shows it as DELETE_COMPLETE.

shivlaks commented 5 years ago

@harmohan-a - repro steps would be nice. Did you modify the A record in any way directly from the console?

I created something similar to @nmussy and verified that on a cdk destroy both the CloudFormation stack is deleted and the A record is deleted from the Route53 console.

const hostedZone = new route53.PublicHostedZone(this, 'shivzone', {
    zoneName: 'shiv.com'
  });

  new route53.ARecord(this, 'A', {
      zone: hostedZone,
      target: route53.RecordTarget.fromIpAddresses('8.8.8.8'),
      recordName: 'test',
  });
harmohan-a commented 5 years ago

hey guys, sorry for being mia. @shivlaks if anything in the route53 had changed. it would have taken super long and thrown an error (the A record doesnt have the same props and cant be deleted) ... i've set up a CI pipeline, so the stack's created on pr and deleted with a teardown step.. i've just tried the same with 1.9.0 but seems to the same issue.

Screen Shot 2019-09-27 at 8 54 55 am

the Alias is still there in route53

Screen Shot 2019-09-27 at 8 56 04 am

i'll check route53 in another 5 mins

harmohan-a commented 5 years ago

SO, i created another project to share reproduction steps.... did everything the same, ran the same commands and it worked :( now, i am not sure whats happening with my project. i'll try to spend sometime debugging it today...

thanks guys !

shivlaks commented 5 years ago

Thanks for checking!

I'm going to resolve this issue for now, but please feel free to re-open if you encounter it again or find a way to reproduce.

mrumpf commented 1 year ago

Could the failure to delete the record be related to externally updating the value of the ARecord? I created an ARecord using CDK and when I destroy the whole stack immediately again, the record gets deleted. But when I update the IP address externally (see for example https://dev.to/aws/amazon-route-53-how-to-automatically-update-ip-addresses-without-using-elastic-ips-h7o) then it seems as if the record does not get deleted upon CDK destroy.