LIVE Instructor-Led Courses
Dismiss
Azure Logic Apps

23 August 2023

How to Integrate Azure Logic Apps with Other Azure Services

Introduction

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.

What are Azure Logic Apps?

Before diving into integrations, let's briefly recap what Azure Logic Apps are and their key capabilities:

  • Cloud-based platform for automating workflows, processes, and business logic
  • Provides a visual designer to model workflows as a series of steps
  • Connectors available for Azure services, SaaS apps, on-premises data
  • Build workflows with a code-free, declarative approach
  • Execute workflows via triggers like timers, inbound HTTP requests, etc
  • Extend capabilities with Azure functions code snippets
  • Integrate apps, data, systems seamlessly

In simpler terms, Azure Logic Apps let you automate scenarios and “connect the dots” across disparate systems fairly easily without writing custom code.

Why Integrate Logic Apps with Other Services?

There are several benefits to integrating Logic Apps with other Azure services:

  • Orchestrate processes across services - Logic apps excel at coordinating complex workflows across many systems
  • Leverage other capabilities - Tap into useful features of Azure services like Functions, Storage, SQL, etc
  • Modularity - Build reusable components and logic
  • Scalability - Each service scales independently for load handling
  • Faster development - Achieve more without managing infrastructure

Now let's look at some examples of how to integrate Logic Apps with other common Azure services.

Integrating Logic Apps with Azure Functions

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:

  • Trigger logic app executions from function code
  • Call functions from workflows to run custom logic

This makes Functions a great complement to Logic Apps for cases where you need a bit more programming capability.

Triggering Logic Apps from Azure Functions

One useful integration pattern is having an Azure Function trigger the execution of a logic app. Some examples:

  • Scheduled jobs - Run logic app on a schedule via timer trigger functions
  • Data changes - Trigger logic app when data changes occur, like new records added to a database
  • File processing - Trigger workflow when a new file arrives in Blob storage

The general steps are:

  1. Create an HTTP triggered function
  2. Call logic app URL from function code, passing any needed data
  3. Logic app runs and does its work
  4. Check logic app run status and logs

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.

Calling Azure Functions from Logic Apps

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:

  1. Create the Azure Function app and functions
  2. Add the "Azure Functions" action in logic app designer
  3. Select the function to call from the connection
  4. Configure inputs and outputs
  5. Handle returned function results

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.

Passing Data Between Logic Apps and Functions

Logic apps and functions can pass data between each other. Some options:

  • Function inputs/outputs - Define parms and return values
  • Trigger metadata - Insert metadata like ids, timestamps
  • Azure storage - Write to blob, queue, table storage
  • HTTP requests - Pass data in API request body, headers, query parms

This enables seamless data flows and integrated workflows leveraging both services' strengths.

Connecting Logic Apps to Azure Storage

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:

  • Execute logic app when a new blob is added
  • Process uploaded files from a container
  • Insert or update SQL data when files arrive
  • Schedule workflows to clean up old blobs

Let's look at the options for connecting Logic Apps to Blob, Queue, Table, or File storage.

Triggering Logic Apps with Azure Storage Events

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

  • On new blob - Runs when a new blob is added
  • On updated blob - Triggers when an existing blob changes

Queue triggers

  • On new queue message - Triggers for each new queue message

File triggers

  • On new file - Triggers when new file added in share
  • On updated file - Runs on changes to existing files

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.

Accessing Azure Storage from Logic Apps

In addition to triggers, logic apps provide actions to directly access Azure Storage like:

  • Blob action - Read or write blobs, folders, containers
  • Queue action - Add, peek, update queue messages
  • Table actions - Insert, update, query table storage

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.

Integrating Logic Apps with Azure SQL Database

Azure SQL Database is a great option for integrating relational data capabilities with Logic Apps.

Some example integrations:

  • Query data from SQL
  • Insert or update records
  • Trigger logic app when data changes
  • Execute stored procedures

Let's go through a few patterns for connecting to SQL from logic apps.

Triggering Logic Apps with SQL Events

A simple trigger is using SQL data changes to kick off workflows. This could be:

  • New rows inserted
  • Row updates
  • Executing stored procedure

For example, you can create a SQL Server row create trigger that fires when new records are inserted.

Steps:

  1. Set up Azure SQL Database, tables, sample data
  2. Create logic app trigger for when rows added
  3. Define columns to pass to workflow
  4. Process new data when logic app runs

This provides an automated flow for responding to database changes.

Querying SQL Data from Logic Apps

To access SQL data from workflows, add the SQL Server - Get rows action.

You can:

  • Query tables or views
  • Map returned columns to workflow
  • Filter rows with WHERE clause
  • Limit number of rows returned

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.

Inserting and Updating SQL Records

To insert or update SQL data:

  • Insert row action inserts a new record
  • Update row updates existing rows

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.

Calling SQL Stored Procedures

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.

Best Practices for Logic App Integrations

Here are some best practices for securely connecting logic apps to other Azure services:

  • Idempotent logic apps - Avoid duplicate actions if steps repeat
  • Handle errors - Use scopes and retries to deal with failures
  • Monitor performance - View metrics in Azure Monitor
  • Security - Encrypt connections and data, restrict access

Let's expand on some of these integration best practices.

Idempotent Logic App Design

An idempotent workflow means logic apps can safely repeat actions without unintended side effects. Ways to make logic apps idempotent:

  • Add logic to check if data exists before creating
  • Design actions to update data, rather than insert duplicates
  • Make stored procedure calls idempotent
  • Generate unique row IDs in data sources
  • Check for duplicate data processing in workflows

This prevents issues with repeated logic app executions.

Handling Errors and Timeouts

Add error handling capabilities like:

  • Retries - Configure retry policies with limits
  • Scopes - Wrap actions in scopes and handle failures
  • Error handling - Route errors to error management flows
  • Alerts - Get notified of failures via alerts

This makes integrations more resilient.

Securing Connections and Data

Security best practices:

  • Encrypt connections and data (HTTPS, SSL)
  • Restrict network access with firewall rules
  • Use managed identities instead of secrets
  • Store connection strings, keys in Azure Key Vault
  • Only access resources explicitly needed

This helps secure critical dataflows.

Monitoring Performance

  • Enable Azure Diagnostics logging for resources
  • View performance metrics and dashboards
  • Set up alerts for failures or latency
  • Send logs to Log Analytics for analysis
  • Check workflow run history and throughput

Monitoring provides visibility into integration workflows.

Summary

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

About the author: Daniel West
Tech Blogger & Researcher for JBI Training

CONTACT
+44 (0)20 8446 7555

[email protected]

SHARE

 

Copyright © 2023 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

POPULAR

Rust training course                                                                          React training course

Threat modelling training course   Python for data analysts training course

Power BI training course                                   Machine Learning training course

Spring Boot Microservices training course              Terraform training course

Kubernetes training course                                                            C++ training course

Power Automate training course                               Clean Code training course