Exercise 2 – Creating a serverless solution using an Azure Logic App
This section will look at the steps to create an Azure Logic App that acts as a social media tracker; when a new tweet is posted that matches the set criteria, an email notification will be sent. Alternatively, it could notify a Teams or Slack channel, for example. This could be the basis for other solutions, such as an RSS feed tracker.
In the following subsections, the process of creating a solution has been segregated into tasks for ease of understanding.
Task – Accessing the Azure portal
- Log into the Azure portal: https://portal.azure.com. Alternatively, you can use the Azure desktop app: https://portal.azure.com/App/Download.
Task – Creating a Logic App
- In the search bar, type the logic apps; click on Logic Apps from the results list.
- From the Logic Apps blade, click on the + Add button on the top toolbar, and then + Consumption.
- From the Basics tab, set the Project Details settings as required.
- Set the Instance details settings as follows:
- Logic App name: Enter a name; this must be globally unique.
- Region: Set this to the region that’s closest to you.
- Leave all other tabs with their default settings.
- Click Review + create.
- On the Review + create tab, review your settings; you may go back to the previous tabs and make edits if required. Once you have confirmed your settings, click Create.
- When the deployment is complete, you will receive a notification that the deployment succeeded. Now, click on Go to resource from the Deployment blade or navigate to the Azure logic app instance.
Task – Creating a Twitter trigger
- From the Logic App blade, click the created Logic App.
- From the left menu, in the Development tools section, click Logic app designer.
- From the Logic Apps Designer blade, scroll down to the Templates section and find the template named Email yourself new tweets about a certain keyword via Outlook:
Tip
You may want to pause for a second as you are scrolling through the templates to look at what else you can create – something that you may want to come back to later to try out. This may include the template that lets you share your tweets to Facebook, posts your Instagram posts to Twitter, notifies you when a file is created in Dropbox, copies a file to OneDrive, and so on.
Figure 5.30 – Logic Apps Designer
- Click on the template to open it and click Use this template.
- From the Logic Apps Designer window, you must connect both your Twitter account and your Outlook account:
• Twitter: Click on the + symbol on the Twitter entry; enter a name for the connection, click Sign in, and follow the prompts to complete the sign-in process.
• Outlook: Click on the + symbol on the Outlook entry; enter a name for the connection, click Sign in, and follow the prompts to
Figure 5.31 – Logic app connections
- Click Continue once both Twitter and Outlook have successful connections; each item will have a green tick next to it.
- In the When a new tweet appears box, enter the search text you wish to use; we will use #AZ900FundamentalsPacktLogicAppTwitterDemo in this example:
Figure 5.32 – Logic app workflow
17. In the Send email box, enter an email address that you want the notifications to be sent to:
Figure 5.33 – Logic app workflow
18. Finally, click Save from the top toolbar. With that, you are ready to test.
Task – Testing the Twitter trigger
19. Click Run Trigger and then Run from the top toolbar:
Figure 5.34 – Logic app Run Trigger
20. Open Twitter and paste in the search text we entered previously; that is, #AZ900FundamentalsPacktLogicAppTwitterDemo:
Figure 5.35 – Twitter post
21. You will receive an email notification of the new tweet:
Figure 5.36 – Logic app email notification of tweet
In this exercise, we looked at creating a Logic App to send an email notification when there is a new Tweet containing a search term. In the following exercise, we will look at creating an IoT solution using an Azure IoT Hub.