amazon-web-servicesamazon-ecsamazon-route53

Can't delete a private hosted zone in AWS Route53


I am unable to delete Private Hosted Zone from console and CLI.

Please check below screen shot

enter image description here

Its throwing following error

The resource hostedzone/Z346QOK8DECBDU can only be managed through servicediscovery.amazonaws.com (arn:aws:servicediscovery:us-east-1:757712384777:namespace/ns-oekfhwgvesmkdb4i)

Private zone has following records enter image description here

I have tried deleting using AWS CLI commands as well

aws servicediscovery list-services
aws servicediscovery delete-service --id=ID-FROM-LIST
aws servicediscovery delete-namespace --id=NS-LIST

This did not work. I got following error

An error occurred (NamespaceNotFound) when calling the DeleteNamespace operation: NS-LIST

An error occurred (ServiceNotFound) when calling the DeleteService operation: ID-FROM-LIST

Please let me know if there is any other way.


Solution

  • Try to delete the AWS ECS service, which is using this hosted zone from AWS console, and then if you have any service discovery resources (like namespace), then delete those using below commands:

    1. Use below command to list services in specific region:

      aws servicediscovery list-services --region <region_name>
      
    2. If no services associated, then try to find the namespaces:

      aws servicediscovery list-namespaces --region <region_name>
      
    3. Then you can delete the namespace as below:

      aws servicediscovery delete-namespace --id <service_discovery_namespace_id> --region <region_name>
      

    From output, It seems you don't have any services listed, but still try with --region option.

    Your namespace_id seems to be incorrectly passed. Its arn is already shown in first error message.

    To delete the private hosted zone:

    To delete a private hosted zone that Amazon ECS created when you created a service using service discovery, delete the Amazon ECS services that are using the namespace, and delete the namespace

    Ref:

    1. https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/hosted-zone-private-deleting.html
    2. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/delete-service.html