Example project of a working Kentico Xperience Azure Function implementation for KX 13.
- Clone this repository down
- Rename
local.settings.json.sample
tolocal.settings.json
- Add in your Connection string to your Azure SQL environment in the local.settings.json file
- Update the Xperience.Kentico.Libraries nuget package to whatever hotfix version of KX 13 you have (minimum 13.0.5 for .NET Core)
- Add any custom classes to the Custom Library, or add your own custom .net Standard / .net Core class libraries (make sure to modify the Startup.cs
RegisterCustomAssemblies();
to include the binaries of any project you are using. - Create your own Functions
In your Azure Portal...
- Add a new Resource -> Function App.
- Set the Runtime stack to .NET and version 3.1
- Host Operating System you can do Linux since this is all .net Core.
- For the plan type, Consumption (serverless) is the cheapest and you can literally get millions of requests for a single dollar.
- Once created, go to Settings/Configuration -> New Application Settings, and add a
CMSConnectionString
App settings with your Azure SQL Connection string
Once it is built, on the Overview click Get Publish Profile
and use this to publish your app from Visual Studio to AF or your preferred means.
Using the publish profile did fail for me with Visual Studio, so Instead you may want to use the normal Publish wizard:
- Publish Azure Function Project
- Select Azure -> Azure Function App (Linux)
- Select your Subscription and find your Azure Function and publish.
You also may want to add a Custom Domain, such as api.mydomain.com
Make sure you have a valid license for whatever domain you do set up for Azure.
Your Database needs to be accessible to your Azure Function, this means your database should be hosted in Azure SQL.
To grant access of your Azure Function to your Azure SQL Server, you can try to setup a VNet, or if you have Premium tier Azure Functions you can get a Static IP and whitelist that on the firewall settings.
If you wish to use the non premium tier, there is still a list of possible IP addresses your Azure Function will use. To get these...
- Go to https://resources.azure.com
- Expand Subscriptions -> [Expand your Subscription] -> Providers -> Microsoft.Web -> Sites
- Find your Azure Function Site in the JSON, and locate the
outboundIpAddresses
andpossibleoutboundIpAddresses
, these will contain a list of IP addresses. - Add all of them to your SQL server's firewall.