top of page

Send e-mails from Azure Data Factory with Azure Logic App

(Part 3/3 of “Getting started with Azure Data Factory”)

ree

Author: Eric Rouach, DBA at Madeira Data Solutions

Date: April 2022




In this demo, I’ll show you how to use an Azure Logic App to alert on an ADF pipeline failure by sending an e-mail.


Pre-requisites:


-An Azure subscription

-An Azure SQL Server

-An Azure SQL database

-An Azure Data Factory

-Completion of parts 1 and 2 of “Getting started with Azure Data Factory”:


Use case:


Our use-case is quite simple: we’ll create a test table in our Azure SQL database and use an ADF pipeline to execute a stored procedure that inserts a row into the test table. Our goal is to create an alert in case of ADF pipeline run failure by calling a Logic App.


Let’s get started!


At this point, let’s assume you have already logged into your Azure SQL Server using SSMS:

ree

Open a new query window using one of the existing databases and create a test table by running the following query:


ree

Now, create a simple stored procedure that will generate an error when executed:


ree

Obviously, the attempt of inserting a NULL value into the not nullable column “AnyText” will fail the stored procedure execution.


Open your ADF studio and select the Author icon:


ree

Create a new pipeline:


ree

Rename it with a meaningful name and close the properties window:


ree

From the Activities pane, under General, drag a Stored Procedure activity to the canvas and rename it:


ree

From the Settings tab, create a new linked service to refer to the Azure SQL database from which the stored procedure is executed:


ree

Give the linked service a meaningful name and choose the Azure SQL Database type:


ree

Provide the Server and Database details and credentials, test the connection and click Create:


ree

Back to the Settings tab, select the stored procedure from the drop-down list:


ree

For testing, debug the pipeline to make sure it fails to run:


ree

It fails as expected:


ree

Back to the Azure portal’s home page, create a Logic App:


ree

Click the Add button, select an existing resource group (or create a new one), give the Logic App a meaningful name and click “Review + Create”:


ree

Wait for the resource deployment:


ree

Once completed, click “Go to resource”.


You now need to design a workflow for your logic app.


At the resource’s home page, from the leftmost pane, select Workflows:



ree

Click the “Add” button to add a new workflow:


ree

Give it a meaningful name, select a State type and click Create:


ree

Clicking on the newly created workflow will direct you to its overview page.


Under the Developer section of the leftmost pane, select “Designer”:


ree

From the workflow designer, you will be able to trigger an e-mail sending whenever a request is sent to the app following a failure of the ADF pipeline:


ree

You need to configure the first operation so that it triggers the e-mail sending “When a http request is received”: from the right window, start typing “request” in the search bar and select the “When a http request is received” icon:


ree

Click the “Save” button to generate the HTTP POST URL:


ree

Copy the generated URL:



ree

Before going on with the Logic App’s workflow design, you need to go back to your ADF pipeline, to add a Web activity that will trigger the HTTP request in case of failure:


From the activities pane, drag and drop a Web activity to the pipeline, name it accordingly and connect it to the previous activity with a failure output (red arrow):


ree

In the Web activity’s settings tab, paste the URL that was generated in the Logic App workflow and select the POST method:


ree

To be able to have dynamic content within the e-mail you whish to send, you should edit the Web activity’s body (which content will be passed to the logic app in a later step).


To edit the body, select the Add dynamic content option:


ree

The Web activity’s body should be in a JSON format, for example, as following:


ree

You may notice that at this point, the “Subject” and “Message” attributes are empty strings (so you can use the logic app dynamically and from several pipelines) whereas System variables are used for all other objects.


Copy your JSON and, back to the logic app’s workflow designer, paste it into the “Request body JSON Schema”:


ree

ree

Click “Done”


The designer right window should look like the following:


ree

The next step is adding an action to the logic app workflow; before configuring the e-mail sending itself, you may customize a variable to hold the e-mail body \ message dynamically; Type “variable” in the search bar and select the Initialize variable operation:


ree

ree

Enter values for Name and Type, then, add dynamic content and select the “Message” and other objects which are available since you have passed them to the HTTP request using the JSON:


ree

Hit “Save” and add a new step to the workflow:


ree

Them, from the list, choose the “Send an email V2” option:


ree

In case you’re not connected to you e-mail provider account, you will prompt to do so. Otherwise, go on with the e-mail sending setup:


ree

Hit “Save”.


The Logic App workflow is now configured!


Before testing the whole process, go back to your ADF pipeline and provide some values for the “Subject” and “Message” objects in the web activity’s body:


ree

Click Ok and try to debug the ADF pipeline. You should expect it to fail and to receive an e-mail.


ree

Indeed, it fails:


ree

Check if you received an e-mail:


ree



*********************Thanks! *********************

コメント


STAY IN TOUCH

Get New posts delivered straight to your inbox

Thank you for subscribing!

bottom of page