Note: This is the second article on the topic of integrating Static Web Apps with resources bound to a virtual network. See the first article for more context: Integrating network isolated backends with Azure Static Web Apps (microsoft.com)
Azure Static Web Apps is the ideal service for hosting modern frontend web apps and static sites on Azure. Many customers rely on Static Web Apps to host their HTML/CSS/JS, React, Vue, Angular, Blazor or NextJS apps (among others!), and they complement these with their APIs, microservices and other services such as databases. At times though, these downstream services are isolated within a virtual network, preventing access from Static Web Apps’ managed Azure Functions. This article explains how we can configure our Static Web Apps to support such access by leveraging Static Web Apps’ linked backends feature.
I’ve previously documented a pattern to do so with the article Integrating network isolated backends with Azure Static Web Apps (microsoft.com). In this article, I document an alternative method that can be used to integrate Static Web Apps within an architecture that has VNET-isolated resources using Function Apps (or Web Apps).
For context, Azure Static Web Apps is an optimized global host for modern frontend web apps, with globally distributed static content hosts, complemented by managed consumption Azure Functions that can be used as APIs or as compute for these frontend web apps. These Azure Functions are managed by the Static Web Apps resource itself.
Architecture diagram of a Static Web Apps resource trying to access network isolated web app or database
Since network isolation of databases or APIs prevents access from Static Web Apps’ managed functions, we can configure our Static Web Apps’ resource to have a linked standalone Azure Function instead of the Static Web Apps-managed Function App. Then, this standalone managed function can be integrated into the virtual network to have access to these network isolated services.
Architecture diagram of Static Web Apps with Azure Functions linked backend, integrated into a virtual network and accessing a web app and database
With this architecture, the Static Web App will proxy requests made to the ‘/api’ endpoint to the publicly available Azure Function resource, and this resource will be able to make requests to any APIs or databases within the virtual network that it is integrated into. Moreover, the connection between the Static Web Apps and the Azure Function will be secured through the linked backends feature.
Note: Static Web Apps supports private endpoints. This means that inbound traffic to the Static Web App can be restricted to a virtual network. However, outbound traffic from the Static Web App or Static Web Apps’ managed function cannot be restricted to a virtual network.
Diagram depicting converting a Static Web Apps without VNET-access into an architecture with VNET-access
We can convert a Static Web Apps with managed functions that does not have access VNet-bound resources, into an architecture that enables such access. Doing so involves the following steps:
At this point, we have the workaround architecture proposed above. Requests made to the default-swa-hostname.azurestaticapps.net/api will be proxied by the Static Web Apps’ hosts to the standalone Azure Function, which can access the virtual network resources because of its virtual network integration.
Screenshot of a request to Static Web Apps' linked backend, showing access to network isolated database
In conclusion, by using Static Web Apps’ linked backends feature, we can securely configure a standalone Azure Function to serve as the Static Web Apps’ linked backend. Then, the Azure Function can be integrated into the virtual network, so that it can access the resources that are bound to that VNet, such as a database or an API.
Read more about architectures to integrate Static Web Apps with network isolated backends here: Integrating network isolated backends with Azure Static Web Apps (microsoft.com)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.