⚡ Comprehensive AWS Route 53 domain management toolkit. Features batch domain deletion, contact updates, CSV input processing, dry-run mode, AWS session tokens, and permanent domain removal. Includes 100+ PHPUnit tests, CI/CD pipeline, and modern PHP 8.3+ architecture with safety features.
This script can permanently delete hosted zones and update domain contact information. These actions cannot be undone. Always test with --dry-run first!
- ✅ Batch deletion of hosted zones from CSV file
- 🔍 Dry-run mode to preview actions without making changes
- 🛡️ Safety confirmation prompt (unless using
--force) - 🔧 AWS connection testing before operations
- 📊 Detailed execution summary
- 🚫 Automatic cleanup of DNS records before zone deletion
- ⏭️ Graceful handling of non-existent domains
- 🔑 Support for AWS session tokens (temporary credentials)
- 🌐 Optional domain registration processing (disable auto-renewal)
- 🗂️ Separate control for hosted zones vs domain registrations
- 📞 Batch update of domain contact information
- 👤 Update admin, registrant, and technical contacts
- 📋 CSV-based domain selection with per-contact-type control
- 🔍 Dry-run mode for contact updates
- 📊 Detailed update summary and error reporting
- 🛡️ Safety confirmation for contact changes
- 📄 JSON-based contact information management
- PHP 8.3+ with Composer
- AWS credentials with Route 53 permissions (including session token support)
- Domains list in CSV format
-
Clone the repository:
git clone https://github.com/erekle1/aws-domain-tools.git cd aws-domain-tools -
Install dependencies:
composer install
-
Configure AWS credentials:
Environment variables take precedence over config file settings.
Method A: Environment Variables (Recommended)
export AWS_ACCESS_KEY_ID="your_access_key" export AWS_SECRET_ACCESS_KEY="your_secret_key" export AWS_SESSION_TOKEN="your_session_token" # Optional: for temporary credentials export AWS_DEFAULT_REGION="eu-central-1"
Method B: .env File (Alternative) Copy
env.exampleto.envand customize:cp env.example .env # Edit .env with your credentialsMethod C: Config File (Fallback) Edit
src/config/aws_config.phpif not using environment variables:return [ 'aws_access_key_id' => 'YOUR_ACCESS_KEY', 'aws_secret_access_key' => 'YOUR_SECRET_KEY', // ... environment variables will override these ];
Method D: AWS CLI Profile If you have AWS CLI configured, the script will use your default profile automatically.
💡 Tip: Check
env.examplefor all available environment variables including deletion control options. -
Add domains to
domains.csv(one domain per line):example.com test.com another-domain.org
You can control script behavior via environment variables (recommended) or config file:
# Deletion control
export DELETE_HOSTED_ZONES="true" # Delete Route 53 hosted zones
export DELETE_DOMAIN_REGISTRATIONS="false" # Process domain registrations
export PERMANENTLY_DELETE_DOMAINS="false" # DANGEROUS! Permanently delete domains
# AWS settings
export AWS_USE_INSTANCE_PROFILE="false" # Use EC2 instance profile
export AWS_CREDENTIAL_TIMEOUT="1" # Credential provider timeoutEdit config/aws_config.php if not using environment variables:
// Domain deletion settings
'delete_hosted_zones' => true, // Delete Route 53 hosted zones
'delete_domain_registrations' => false, // Process domain registrations
'permanently_delete_domains' => false, // DANGEROUS! Permanently delete domains- Environment variables override config file settings
- Hosted Zone Deletion: Completely removes DNS zones from Route 53
- Domain Registration Processing: Disables auto-renewal and provides transfer instructions
- Set
DELETE_DOMAIN_REGISTRATIONS="true"only if you want to process registered domains
Create a contacts.json file in the project root with your contact information:
{
"admin_contact": {
"firstName": "John",
"lastName": "Doe",
"contactType": "PERSON",
"organizationName": "Your Organization",
"addressLine1": "123 Main Street",
"city": "Your City",
"state": "ST",
"countryCode": "US",
"zipCode": "12345",
"phoneNumber": "+1.5551234567",
"email": "admin@yourdomain.com",
"extraParams": []
},
"registrant_contact": {
"firstName": "Jane",
"lastName": "Smith",
"contactType": "PERSON",
"organizationName": "Your Organization",
"addressLine1": "123 Main Street",
"city": "Your City",
"state": "ST",
"countryCode": "US",
"zipCode": "12345",
"phoneNumber": "+1.5551234567",
"email": "registrant@yourdomain.com",
"extraParams": []
},
"tech_contact": {
"firstName": "Tech",
"lastName": "Support",
"contactType": "PERSON",
"organizationName": "Your Organization",
"addressLine1": "123 Main Street",
"city": "Your City",
"state": "ST",
"countryCode": "US",
"zipCode": "12345",
"phoneNumber": "+1.5551234567",
"email": "tech@yourdomain.com",
"extraParams": []
}
}Create a CSV file specifying which domains to update and which contact types:
domain_name,update_admin,update_registrant,update_tech
example.com,true,true,true
test-domain.com,false,true,false
another-domain.org,true,false,true
CSV Columns:
domain_name: The domain to updateupdate_admin:trueto update admin contact,falseto skipupdate_registrant:trueto update registrant contact,falseto skipupdate_tech:trueto update tech contact,falseto skip
PERMANENTLY_DELETE_DOMAINS="true": Uses AWSdeleteDomainAPI to IRREVERSIBLY delete domain registrations- NO REFUNDS: You will not receive any refund for deleted domain costs
- IMMEDIATE RELEASE: Domains are released back to public registry and can be registered by anyone
- NO RECOVERY: Once deleted, domains cannot be recovered
- USE WITH EXTREME CAUTION: Only enable for domains you absolutely never want again
php aws-domain-manager.php --delete-domains --dry-runThis shows what would be deleted without making any changes.
php aws-domain-manager.php --delete-domainsThis will:
- Test AWS connection
- Show domains to be deleted
- Ask for confirmation
- Delete hosted zones
php aws-domain-manager.php --delete-domains --forcephp aws-domain-manager.php --update-contacts --admin-contact --tech-contact --dry-runphp aws-domain-manager.php --update-contacts --admin-contact --tech-contactphp aws-domain-manager.php --update-contacts --admin-contact --registrant-contact --tech-contactphp aws-domain-manager.php --update-contacts --admin-contact --force--delete-domains: Delete domain hosted zones and registrations--update-contacts: Update domain contact information
--dry-run: Preview actions without making changes--force: Skip confirmation prompt (dangerous!)--help,-h: Show help message
--admin-contact: Update admin contact for domains--registrant-contact: Update registrant contact for domains--tech-contact: Update technical contact for domains
- Tests AWS connection to ensure credentials work
- Reads domains from the CSV file
- Finds hosted zones for each domain in Route 53
- Deletes DNS records (except NS and SOA)
- Deletes the hosted zone itself
- Checks if domains are registered with Route 53 Domains
- Disables auto-renewal to prevent automatic charges
- Provides transfer instructions for complete domain removal
- Note: AWS doesn't allow direct domain deletion - you must transfer out manually
- Loads contact information from
contacts.json - Reads domain list from
domains_to_update.csv - Tests AWS connection to Route 53 Domains service
- Updates specified contact types for each domain
- Provides detailed summary of successful/failed updates
- Supports dry-run mode to preview changes without applying them
- Provides comprehensive summary of all operations
🔧 Testing AWS connection...
✅ AWS connection successful
Found 3 domains to process:
- example.com
- test.com
- another-domain.org
⚠️ WARNING: This will permanently delete 3 hosted zones from AWS Route 53!
This action cannot be undone. Are you sure you want to continue? (yes/no): yes
Processing domain: **example.com**
-> Found Hosted Zone ID: Z1234567890
--> Deleting record: www.example.com (A)
--> All non-essential records deleted successfully.
✅ Successfully deleted Hosted Zone for 'example.com' (ID: Z1234567890).
============================================
📊 EXECUTION SUMMARY
============================================
Total domains processed: 3
✅ Successful deletions: 2
❌ Failed deletions: 0
⏭️ Skipped domains: 1
Script finished.
- Never commit
aws_config.phpto version control - Use IAM users with minimal required permissions
- Always test with
--dry-runfirst - Double-check domain list before running
- Keep backups of important DNS configurations
route53:ListHostedZonesroute53:ListHostedZonesByNameroute53:ListResourceRecordSetsroute53:ChangeResourceRecordSetsroute53:DeleteHostedZone
route53domains:GetDomainDetailroute53domains:DisableDomainAutoRenewroute53domains:ListDomains(optional, for bulk operations)
route53domains:DeleteDomain⚠️ IRREVERSIBLE OPERATION
Note: Route 53 Domains permissions are only available in us-east-1 region.
- Check your AWS credentials in
src/config/aws_config.php - Verify your AWS region is correct
- Ensure your AWS user has Route 53 permissions
- If using temporary credentials, verify your session token is not expired
- Try setting
use_instance_profiletofalsein config if not on EC2
- The domain doesn't have a hosted zone in Route 53
- Check if the domain is spelled correctly
- The script will skip these domains automatically
- The hosted zone might have dependent resources
- Some AWS errors require manual intervention
- Check the AWS console for more details
aws-domain-deleter/
├── aws-domain-manager.php # Main domain management script (v3.0 - supports both deletion and contact updates)
├── domains.csv # List of domains to delete (213 domains ready)
├── src/ # Source code (object-oriented architecture)
│ ├── Application.php # Main application orchestrator
│ ├── AWS/
│ │ ├── CredentialsManager.php # AWS credentials handling
│ │ └── ClientFactory.php # AWS client factory
│ └── Services/
│ ├── DomainManager.php # Domain validation & loading
│ ├── Route53Service.php # Route 53 hosted zone operations
│ ├── Route53DomainsService.php # Route 53 domain registration operations
│ └── UserInterface.php # User interaction & display
├── config/
│ ├── aws_config.php # AWS credentials & settings
│ └── helpers.php # Helper functions
├── vendor/ # Composer dependencies
├── composer.json # PHP dependencies (latest AWS SDK)
├── env.example # Environment variables setup guide
└── README.md # This documentation
If you encounter issues:
- Run with
--dry-runto see what would happen - Check AWS console for hosted zone status
- Verify your AWS permissions
- Review the error messages in the output
Erekle Kereselidze
- GitHub: @erekle1
- Email: erekle.kereselidze2@gmail.com
Contributions are welcome! Please read the CONTRIBUTING.md guide for details on how to contribute to this project.
This project is licensed under the MIT License - see the LICENSE file for details.