Hello EnterpriseArchitect,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
Problem
Sequel to your questions, I understand that you want to figure out how to stop or shut down certain parts of the app when they're not needed, like outside regular work hours. This means looking at things like the App Service, Service Bus, Azure Function, and Azure Key Vault, and making sure they're only running when necessary. By doing this, your company can cut down on costs while still making sure the app runs smoothly when it's supposed to.
Scenario
The Company Communicator application utilizes various Azure resources to facilitate message composition, queuing, processing, and delivery. During non-operational hours, such as nights and weekends, these resources continue to run, resulting in unnecessary costs. To address this issue, the company seeks to implement cost-saving measures by identifying which Azure objects can be suspended or turned off outside of business hours.
Solution
This prescribed solution was based on the scenario given and your questions, while focusing on the problem statement. However, given it a second thought from my side, your questions were environment base, therefore. To save on running costs, you can consider suspending or turning off the following Azure objects outside of business hours:
App Service: If the message compose experience and messaging endpoint for the bot are not required outside of business hours, you can consider scaling down or stopping the Azure App Service during non-operational hours.
Service Bus: Since messages are queued on a service bus queue to be processed by an Azure Function, you may not need the Service Bus to be active outside of business hours. You could explore stopping or scaling down the Service Bus during these times.
Azure Function: If message processing is not critical outside of business hours, you can suspend or scale down the Azure Function that picks up messages from the queues, prepares recipients, and delivers them.
Azure Key Vault: Azure Key Vault typically doesn't consume many resources when idle. However, if there are secrets, certificates, or connection strings that are only required during business hours, you could explore implementing Key Vault access policies or automations to restrict access or operations outside of these hours.
Author Bot Registration and User Bot Registration: If these registrations are not actively used or required outside of business hours, you can explore options to suspend or scale down the corresponding Azure resources associated with these registrations during non-operational hours.
Finally
Once you identify any from above, that will answer your question.
However, to solve the problem and address the questions outlined, you can follow these steps:
STEP 1:
Analyze usage patterns to determine which Azure resources remain idle outside of business hours.
- Focus on resources like App Service, Service Bus, Azure Function, and Azure Key Vault mentioned in the user inputs.
- Review Azure Monitor metrics and logs to analyze resource utilization patterns.
- Identify resources with low activity or usage outside of business hours.
STEP 2:
Utilize Azure Automation or Azure Functions to automate the process of suspending or scaling down resources during non-operational hours.
- Create PowerShell scripts or Azure Resource Manager (ARM) templates to perform resource scaling or suspension based on predefined schedules.
- For example, you can create PowerShell scripts or ARM templates to scale down or suspend App Service, Service Bus, Azure Function, and Azure Key Vault.
Utilize Azure Automation to schedule and execute these scripts automatically.
# Connect to Azure account
Connect-AzAccount
# Get the Azure Web App resource
$appService = Get-AzWebApp -ResourceGroupName "YourResourceGroup" -Name "YourAppServiceName"
# Scale the App Service to 0 instances
$appService | Set-AzWebApp -NumberofInstances 0
STEP 3:
Define schedules for resource suspension or scaling based on business hours and non-operational hours.
Utilize Azure Scheduler or Azure Logic Apps to trigger automation scripts at specified times.
- Define schedules using Azure Scheduler or Azure Logic Apps to trigger the automation scripts during non-operational hours.
Set up recurring schedules based on business hours and weekends/nights.
STEP 4:
Implement logic in the Azure Function to monitor queue length and scale dynamically.
- Configure Azure Function settings to automatically scale based on queue activity.
// Azure Function to process messages from Service Bus Queue
public static async Task Run([ServiceBusTrigger("your-queue-name", Connection = "ServiceBusConnection")] string myQueueItem, ILogger log)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
// Add your message processing logic here
// Get queue length
int queueLength = await GetQueueLength("your-queue-name");
// Scale dynamically based on queue length
if (queueLength > 100)
{
// Scale out
log.LogInformation("Scaling out Azure Function to handle increased load...");
// Code to scale out Azure Function
}
}
public static async Task<int> GetQueueLength(string queueName)
{
// Code to get queue length from Service Bus
}
# PowerShell to Suspend the Azure Function
# Connect to Azure account
Connect-AzAccount
# Get the Azure Function App resource
$functionApp = Get-AzFunctionApp -ResourceGroupName "YourResourceGroup" -Name "YourFunctionAppName"
# Suspend the Azure Function
$functionApp | Stop-AzFunctionApp
STEP 5:
Implement access policies in Azure Key Vault to restrict access during non-operational hours.
- Set up scheduled access policies to allow access only during required times.
By following the above steps and utilizing appropriate automation and scheduling techniques, along with monitoring and scaling strategies, you can effectively optimize costs for the Company Communicator application on Azure while ensuring seamless functionality during operational hours. I assure you of 90% success rate.
References
Source: Microsoft Bing. Accessed, 5/5/2024.
Source: 15% of the procedures were provided by Copilot, which was reaffirm and adjusted by me.
Kindly utilize the additional resource available by the right side of this page
Accept Answer
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
Please remember to "Accept Answer" if answer helped, so that others in the community facing similar issues can easily find the solution.
Best Regards,
Sina Salam