23 August 2023
Azure Logic Apps provide a great way to automate workflows and business processes in the cloud. With Logic Apps, you can integrate various Azure services together to build end-to-end solutions without writing any code.
JBI Training can supply a complete solution to all of your tech training requirements. If you are considering a Azure Logic Apps course, please feel free to get in contact and we can supply exactly what you need for yourself or your team.
There are many examples of how Logic Apps can connect to other Azure resources like Azure Functions, Azure Storage, Azure SQL Database, and more. Integrating Logic Apps with other services unlocks many possibilities like triggering logic apps when data changes, querying data sources, executing logic on-demand, and inserting data into external systems.
In this article, we'll cover some of the most common integration patterns and examples using Azure Logic Apps. We'll look at integrating logic apps with Azure Functions, Azure Storage, and Azure SQL Database. We'll also discuss some best practices around handling errors, monitoring, and security when connecting logic apps to other Azure services.
Before diving into integrations, let's briefly recap what Azure Logic Apps are and their key capabilities:
In simpler terms, Azure Logic Apps let you automate scenarios and “connect the dots” across disparate systems fairly easily without writing custom code.
There are several benefits to integrating Logic Apps with other Azure services:
Now let's look at some examples of how to integrate Logic Apps with other common Azure services.
Azure Functions are an effective way to extend Logic Apps with custom code snippets and background processing capabilities. There are a couple patterns for connecting Logic Apps and Functions:
This makes Functions a great complement to Logic Apps for cases where you need a bit more programming capability.
One useful integration pattern is having an Azure Function trigger the execution of a logic app. Some examples:
The general steps are:
Let's walk through a simple example of triggering a logic app from an HTTP triggered function.
First, we'll create the function:
// HTTP triggered function
[FunctionName("TriggerLogicApp")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequest req,
ILogger log)
{
// Call logic app URL
HttpClient httpClient = new HttpClient();
var response = await httpClient.PostAsync("https://logicappurl.azurewebsites.net/workflows/workflowname/triggers/manual/paths/invoke?api-version=2016-06-01", null);
return new OkObjectResult("Logic app triggered");
}
We call the logic app trigger URL from the function code via a POST request. This will kick off the workflow.
After triggering the logic app, we could also choose to check the status by querying the Run metadata like status
, startTime
, etc.
The other direction of integration is invoking function code from a logic app workflow.
This is great for scenarios where you want to perform some custom logic or processing as part of your automated workflow.
To call functions from logic apps:
For example, you could insert data into a database from a logic app as follows:
// Logic app workflow
"steps": [
// Call function to insert data
{
"function": {
"id": "/subscriptions/xxxxxx/resourceGroups/xxxxxxxx/providers/Microsoft.Web/sites/functionapp/functions/InsertData",
"type": "AzureFunction"
},
"inputs": {
"body": "@{triggerBody()}"
},
"runAfter": {}
}
]
This provides a serverless way to run code without managing infrastructure.
Logic apps and functions can pass data between each other. Some options:
This enables seamless data flows and integrated workflows leveraging both services' strengths.
Azure Storage is another essential service that integrates well with Logic Apps. You can trigger logic app execution based on storage events, or read/write data from a workflow.
Some examples of Logic App + Storage integrations:
Let's look at the options for connecting Logic Apps to Blob, Queue, Table, or File storage.
One trigger option is starting a logic app workflow when files or data change in Azure Storage.
Some of the storage event triggers available:
Blob triggers
Queue triggers
File triggers
Let's look at a simple example using blob storage.
First, we create a storage account and a blob container. We add some sample files to the container.
Next, set up the When a blob is added or modified trigger on the container. This will fire each time a new blob arrives.
The logic app can then process the new blobs that caused the trigger. For example, it could copy blobs to another location, send email alerts, update a database, or kick off another workflow.
In addition to triggers, logic apps provide actions to directly access Azure Storage like:
For example, you could retrieve a blob based on filename:
// Logic app flow
Get blob content (action)
Path - container/filename.txt
@body('<action-name>')
Or update a Storage Queue:
// Logic app flow
Push to queue (action)
Message - Hello World!
This makes it easy to leverage Azure Storage capabilities from your workflows.
Azure SQL Database is a great option for integrating relational data capabilities with Logic Apps.
Some example integrations:
Let's go through a few patterns for connecting to SQL from logic apps.
A simple trigger is using SQL data changes to kick off workflows. This could be:
For example, you can create a SQL Server row create trigger that fires when new records are inserted.
Steps:
This provides an automated flow for responding to database changes.
To access SQL data from workflows, add the SQL Server - Get rows action.
You can:
For example:
// Logic app workflow
Get_rows (action)
Server - sqlserver
Database - databasename
Query - SELECT * FROM table
This simplifies passing SQL data into your logic apps.
To insert or update SQL data:
You can map logic app data fields to column values in the actions.
Example adding a new row:
// Logic app workflow
Insert_row (action)
Server - sqlserver
Database - databasename
Table - tablename
Columns:
@{firstColumn:'value1'}
@{secondColumn:'value2'}
This enables pushing data into SQL from workflows.
Logic apps can execute stored procedures using the SQL Server - Execute stored procedure action.
You enter the sproc name, map parameters, and handle sproc outputs back into the workflow.
This gives additional options for custom SQL logic and integration.
Here are some best practices for securely connecting logic apps to other Azure services:
Let's expand on some of these integration best practices.
An idempotent workflow means logic apps can safely repeat actions without unintended side effects. Ways to make logic apps idempotent:
This prevents issues with repeated logic app executions.
Add error handling capabilities like:
This makes integrations more resilient.
Security best practices:
This helps secure critical dataflows.
Monitoring provides visibility into integration workflows.
Connecting Azure Logic Apps to other services like Azure Functions, Storage, and SQL expands workflow automation capabilities.
Triggering logic apps from external systems enables execution based on events. Calling logic from workflows allows custom processing anywhere needed
If you enjoyed this article be sure to check out Azure Logic Apps: How to create a logic app
CONTACT
+44 (0)20 8446 7555
Copyright © 2024 JBI Training. All Rights Reserved.
JB International Training Ltd - Company Registration Number: 08458005
Registered Address: Wohl Enterprise Hub, 2B Redbourne Avenue, London, N3 2BS
Modern Slavery Statement & Corporate Policies | Terms & Conditions | Contact Us