#6: Serverless integration with Logic Apps
Previous: #5: Hosting and securing your files with Azure Storage
Disclaimer: This blog post is not officially endorsed by Microsoft.
Out of all of the blogs I've written so far, it can probably be argued that this has the most confusing title. Serverless? Integration? Logic Apps?! Too many buzzwords!! Let's break this down.
What are Logic Apps?
I'm going to start off by explaining what a Logic App is. A Logic App is exactly that: an app that executes on some defined logic. In Logic Apps there are two main pillars that form the basis of a workflow: a trigger and an action. A trigger is essentially something that causes the app to run (i.e. the actions), usually when a condition is met or a specific event happens. An example of a trigger could be whenever a Tweet is posted with a certain hashtag. An Action is something that gets executed after a Trigger is fired or it could even follow from another action. Essentially, actions are the steps that occur after the trigger condition is met. For example, an action could involve sending the link of the Tweet with the certain hashtag to your email address. This is essentially how integration is achieved! Integration is defined as a service or component that exists to join two separate platforms (or subsystems) together. In our example above, we are integrating our application with Twitter. Integration is made possible by our Logic App that refreshes every moment or so, waiting for its trigger to fire. When the Trigger is fired, the Logic App will send off that email and voila!, you will have integrated two separate platforms together.
Another large benefit of using Logic Apps for integration is the fact that they are Serverless. Meaning, there are no servers that need to be managed by you to make the integration happen. The word "serverless" tends to be a bit misleading as it gives you the impression that there are no servers involved, but this is not the case. I can confirm that there are lots of servers involved here! The best thing about Logic Apps is that you don't need to write a single line of code. The drag and drop visual designer makes automating your business workflows and processes a tireless task, often creating a fully-fledged solution in minutes.
Pricing
Pricing is defined by the triggers, actions and connectors that are used in each run of a Logic App (pricing differs in ISEs, but I won't cover that in this blog).
- Triggers: AUD $0.000039
- Actions: AUD $0.000179
- Connectors: AUD $0.001373
A Connector is essentially a built-in service that provides quick access to other platforms, services, systems or apps. There are different types of connectors such as Enterprise connectors and Custom connectors. Connectors may either act as a trigger or an action. For example, Logic Apps have a native Twilio connector. Twilio is a third-party SMS service API that allows developers to programmatically send text messages to their customer's phones. Ever received an automated text message and wondered who is actually sending them and how? Twilio does exactly that, it automates the sending of SMS messages. Logic Apps having a native Twilio connector means that you can easily incorporate SMS messaging in your business workflow! Let's put this in a real-life scenario. Imagine if you have a device that records temperature and humidity and you wish to be notified by SMS if the temperature goes above 40oC. The Logic App will listen and subscribe to the data-stream sent from the device and if it finds an instance where the temperature is above the specified threshold of 40oC, the Logic App will be triggered and execute the actions under it, which in this case is to send an SMS text with a message saying something like "ALERT: The temperature is above 40oC".
Note: The above architecture is NOT good design and is only for expressing how Logic Apps work.
Hopefully by now you have a good idea of what a Logic App is, how integration is achieved, the differences between connectors, triggers and actions and how business workflows can be developed through the design and use of these different connectors. For a list of the available connectors, please see here.
Hands-on lab: Monitoring your website availability with Logic Apps
In this hands-on lab we will be monitoring the availability of a Web App. This is usually provided by Azure Monitor but for the purpose of demonstrating Logic Apps, we will do this process ourselves!
Step 1: Create a Logic App. By now you should have a good idea how to navigate the Azure Portal. If you don't please refer back to the previous blogs! Ensure it looks like the below screenshot.
Step 2: After creating the Logic App, it should take you to the Logic App Designer page. Somewhere on that page you should see the Recurrence trigger, go ahead and click on it. A Recurrence trigger is a time-based (Timer) trigger. In simple terms, this trigger uses some specified interval of time (e.g. every 5 minutes) to trigger the workflow.
Step 3: Add a new step. Under the "Control" bracket, choose Scope.
Step 4: Click Add an action. Search for the HTTP trigger and click on HTTP. In the Method drop down, select GET.
Step 5: Open a new tab and go to the Azure Portal. Create and deploy an App Service resource. If you need assistance creating an App Service, please refer to my previous blogs. Once deployed, copy the link of the website (should look something like https://logicapptesting.azurewebsites.net) and insert it into the URI section of the HTTP trigger.
Step 6: Add a new step under the Scope and add a Condition under the "Control" bracket. Once the Condition action opens, change "And" to "Or" and follow the below screenshot.
The "result" function is: result('Scope')[0]['status']
Next, click on the 3 dots on the top right corner of the Condition box and click on "Configure run after". Check all four boxes and click Done.
Step 7: Under the True section in the Condition, click Add an action. Search "Office 365 Outlook" or any other available email provider of your choosing such as Gmail. (Note: you may need to sync your Outlook/Gmail account when doing this part).
Step 8: Find the "Send an email" action as shown below.
Step 9: Fill out the To, Subject and Body fields as appropriate (e.g. in the Body you can write something like "Your website is down").
Step 10: Click Save at the top left corner. Confirm the Logic App workflow looks like the below screenshot.
Step 11: Go to your Web App and stop it from running. Then go to the Logic App and click "Run" next to the "Save" button. Hopefully, it will attempt to contact the website but it will be unavailable. Then the Condition will be executed and return an Error, which then proceeds to send the email.
If you received an email, congrats! You have just set up and deployed your first serverless integration app on Azure.
Like the last blog, if you had any issues or further questions please feel free to send me a message on LinkedIn and I will be more than happy to help you!
What can I expect in the next blog post?
The next blog post will be on Azure DevOps and Pipelines to achieve CI/CD (Continuous Integration/Continuous Development/Delivery), creating software production workflows, automating builds, version control and much more. Till then!
This will be delivered mid-December due to University exams. Thank you for your patience!