PEAKUP.Azure.Services is a .NET Core project that provides a set of services for scaling Azure resources such as Web Apps and SQL databases. It leverages the Azure Management Fluent SDK to interact with Azure resources.
-
Create an Azure Application
- Go to the Azure portal (https://portal.azure.com).
- Navigate to "Azure Active Directory" in the left-hand menu.
- Click on "App registrations" and then click "New registration".
- Provide a name for the application, select the supported account types, and specify the redirect URI (if required).
-
Assign Access Control (IAM) Permissions
-
For Web App Management:
- Navigate to the desired resource group that contains the target Web App.
- Click on "Access control (IAM)" in the left-hand menu.
- Click "Add a role assignment".
- In the "Role" dropdown, search for and select "Web Plan Contributor" and "Website Contributor".
- In the "Select" dropdown, search and select the application you created in Step 1.
- Click "Save" to assign the roles.
-
For SQL Server and Database Management:
- Navigate to the desired resource group that contains the target SQL Server and database.
- Click on "Access control (IAM)" in the left-hand menu.
- Click "Add a role assignment".
- In the "Role" dropdown, search for and select "SQL DB Contributor", "SQL Managed Instance Contributor", and "SQL Server Contributor".
- In the "Select" dropdown, search and select the application you created in Step 1.
- Click "Save" to assign the roles.
-
-
Update Application Credentials in the Code
In the
Program.cs
file of thePEAKUP.Azure.Services
project, update the following variables with the values obtained from Step 1:var credentials = new AzureApplicationCredentials() { ClientId = "Your_Client_Id", // Replace with the Application (client) ID ClientSecret = "Your_Client_Secret", // Replace with the Client secret TenantId = "Your_Tenant_Id", // Replace with the Directory (tenant) ID SubscriptionId = "Your_Subscription_Id" // Replace with your Azure subscription ID };
- .NET 6.0 LTS or later
- Azure subscription with appropriate permissions and credentials
- Clone the repository or download the source code.
- Open the solution in Visual Studio or your preferred code editor.
Before running the application, make sure to update the Azure application credentials and resource information in the Program.cs
file.
// Update these values with your actual Azure application credentials
var credentials = new AzureApplicationCredentials()
{
ClientId = "Your_Client_Id",
ClientSecret = "Your_Client_Secret",
TenantId = "Your_Tenant_Id",
SubscriptionId = "Your_Subscription_Id"
};
// Update these values with your actual Azure resource information
var webAppResources = new WebAppCredentials()
{
ResourceGroupName = "Your_Resource_Group",
WebAppName = "Your_Web_App_Name",
WebAppServicePlanName = "Your_Web_App_Service_Plan_Name"
};
var sqlResources = new SQLCredentials()
{
ResourceGroupName = "Your_Resource_Group",
SqlServerName = "Your_SQL_Server_Name",
DatabaseName = "Your_Database_Name"
};
To scale an Azure Web App, follow these steps:
- Create an instance of
WebApplicationService
using the provided credentials and resource information, same applies for the SQL Server!
var webAppServiceScaler = new WebApplicationService(credentials, webAppResources);
webAppServiceScaler.CreateAzureClient();
IWebApp webApp = webAppServiceScaler.GetWebApp();
//Provide how many scaled instances desired with this pricing tier!
webAppServiceScaler.Scale(PricingTier.StandardS1, 2);
To scale an Azure SQL Server, follow these steps:
- Create an instance of
SQLDatabaseService
using the provided credentials and resource information:
// Update these values with your actual Azure application credentials
var credentials = new AzureApplicationCredentials()
{
ClientId = "Your_Client_Id",
ClientSecret = "Your_Client_Secret",
TenantId = "Your_Tenant_Id",
SubscriptionId = "Your_Subscription_Id"
};
// Update these values with your actual Azure resource information for the SQL Server
var sqlResources = new SQLCredentials()
{
ResourceGroupName = "Your_Resource_Group",
SqlServerName = "Your_SQL_Server_Name",
DatabaseName = "Your_Database_Name"
};
var sqlDatabaseService = new SQLDatabaseService(credentials, sqlResources);
sqlDatabaseService.CreateAzureClient();
var desiredPlan = ServiceObjectiveName.S1;
ISqlDatabase updatedSqlDatabase = sqlDatabaseService.Scale(desiredPlan);