Some time ago, my colleague Raphael Poumarede shared how to Reduce the Azure bill when you are not using the SAS Viya environment.
To be even more cost effective in cloud resources, a common approach is to schedule the stop and the start of your Kubernetes cluster at fixed hours. At the same time and to not limit the SAS users, the decision is usually taken to delay the stop “as late as possible” in the evening and to anticipate the restart “as soon as possible” in the morning.
What if the SAS Users can play a role to optimize the cloud costs?
What if the SAS Users can decide to postpone a stop or anticipate a start by themself without anyone to be involved?
In this post I will share an example on how this can be achieved. This example will mainly be using Azure resources as they simplify the integration with MS Teams, but the concept can be adapted to any cloud provider.
Microsoft Teams Microsoft Teams is a collaboration platform for communication, meetings, and teamwork within organizations. It integrates with Microsoft 365 apps and offers features like chat, video conferencing, and document sharing. We are using Teams as a “simple” way to trigger an action.
Azure Logic Apps Azure Logic App automates tasks and integrates apps and services in the cloud. It offers a visual interface for creating workflows without extensive coding. This simplifies and accelerates business processes.
We are using Logic App as a sequencer for all tasks.
Azure DevOps Azure DevOps is Microsoft's integrated suite of development tools and services. It covers the software development lifecycle, enabling teams to collaborate, automate workflows, and deliver high-quality software efficiently.
We are using Azure DevOps to get access to external commands (kubectl) not available in Logic App.
The following screenshot shows an example of implementing this approach.
Select any image to see a larger version.
Mobile users: If you do not see this image, scroll to the bottom of the page and select the "Full" version of this post.
Step1: The user (here David) sends a message to start the SAS Viya platform.
Step 2: The system will respond that the received has been received. This is only to confirm that the request has been received until the SAS Viya platform will be up-and-running.
Step 3: When the SAS Viya platform is completely up-and running the system sends the message in the channel with the URL of the environment.
Step1: The user (here David) sends a message to stop the SAS Viya platform.
Step2: The system sends the message when the SAS Viya platform is completely stopped.
The general idea is to use the Logic App as a sequencer for the following steps:
Here is the graphical overview of the Logic App I designed in Microsoft Portal.
Now let’s describe each node of this Logic App.
|
When keywords are mentionedStep Type: Microsoft Teams: When keywords are mentioned This is where you will define your “trigger”. I used the keyword StartSASViya in Team “SAS Viya Environment” in the channel “Personal -Latest”. Hints: Don’t use # in the keywords |
|
HTTP Post message in a chat or channelStep Type: HTTP This step is a call to your predefined WebHooks. The content of the message is in JSON format, click on the image to see the content |
|
List resources by resource groupStep Type: Azure Resource Manager This step will retrieve all Azure resources in the “fradae-stable-202308-rg” resource group. |
|
Get Flexible ServersStep Type: Variables Built-in This step will filter the previous output only with object with type: “Microsoft.DBforPostgreSQL/flexibleServers” |
|
For each Flexible ServerStep Type: For each (Control) This step will loop on each “Flexible Server” in the resource group. This step will first get the full ID of the Flexible Server in this format: /subscriptions/c1b1cbfa-699a-47f5-95c5-aaaaaaaaaaaa/resourceGroups/fradae-stable- 202308/rg/providers/Microsoft.DBforPostgreSQL/ flexibleServers/fradae-stable-202308-default-flexpsql Then we will extract the variable needed to be able to start the Flexible Server through an API :
The method used is to “Split” the ID, (i.e for the Subscription ID : split(outputs('Extract_PG_ID'),'/')[2]). This will extract c1b1cbfa-699a-47f5-95c5-aaaaaaaaaaaa. The same method is used for the other needed variables. The last step is the actual start of the “Flexible Server” using the API described here
|
|
Get AKS Clusters (same logic as for Flexible Server)Step Type: Variables Built-in This step will filter the previous output only with object with type: “Microsoft.ContainerService/managedClusters” |
|
For each AKS Cluster (same logic as for Flexible Server)Step Type: For each (Control) The last step is the actual start of the “AKS Cluster” using the API described here |
|
Send an HTTP request to Azure DevOpsStep Type: Send an HTTP requests to Azure DevOps This will trigger a DevOps pipeline (mainly to be able to use a kubectl command) to wait until the SAS Viya Platform will be fully functional. Then the pipeline will send the completion message in the same predefined WebHooks. The content of the request Body is in JSON format, click on the image to see the content Hints: The JSON object resources.repositories.self.refName is mandatory and should reflect your Azure DevOps branch name of the pipeline you want to execute |
This example shows how SAS Users can be an active part of the cloud cost optimization. Some other examples could be implemented using the same approach:
I hope this brief example of the integration between Azure Logic App / Microsoft Teams and the SAS Viya platform will be useful to you.
Special thanks to Thomas and Pooja as this example was inspired by the combination of this post from Thomas Stringer, Schedule AKS Clusters to Start and Stop Automatically and a post from my colleague Pooja Dalal and customized it to add the MS Teams interaction.
Find more articles from SAS Global Enablement and Learning here.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.