How to automatically revalidate custom domain mapped to SWA

alabitosin58@gmail.com 0 Reputation points
2024-10-25T11:47:39.04+00:00

How can I automatically revalidate custom domain mapped to a Static Web App instead of creating a TXT record manually every 6 months? or revalidation of custom domain is done manually?

Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
{count} votes

1 answer

Sort by: Most helpful
  1. Shree Hima Bindu Maganti 6,350 Reputation points Microsoft External Staff Moderator
    2024-10-28T08:36:54.3766667+00:00

    Hi @alabitosin58@gmail.com ,
    welcome to the Microsoft Q&A Platform!
    To automatically revalidate a custom domain mapped to an Azure Static Web App (SWA), you can use Azure DNS and script-based automation to periodically update the TXT record for domain ownership verification:

    1. Automated Revalidation with Azure DNS:
    • If you manage your DNS with Azure DNS: You can use Azure CLI or PowerShell scripts to automate the re-addition of the TXT record before it expires.
    • Create a script that runs periodically (such as every 5-6 months) to check if the revalidation is due.
    • Use Azure CLI or Azure PowerShell within the script to update or add the TXT record required for validation.
    • Deploy this script in an Azure Function or Azure Logic App to ensure it runs automatically at the desired interval.
    • Here’s a simplified example of a PowerShell script to add or update a TXT record in Azure DNS:
        $resourceGroupName = "YourResourceGroup"
        $zoneName = "yourdomain.com"
        $recordSetName = "_dnsauth.swa"
        $txtValue = "YourVerificationToken"
        # Authenticate with Azure
        Connect-AzAccount
        # Add or update the TXT record in Azure DNS
        New-AzDnsRecordSet -Name $recordSetName -RecordType TXT -ZoneName $zoneName -ResourceGroupName $resourceGroupName -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -Value $txtValue) -Force
        
        
      
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.