Azure Functions and Logic Apps

I wanted to create a simple Azure Function to make an HTTP GET Request to my website, which is hosted on the cheapest GoDaddy subscription. This subscription is on shared hosting and I don’t have much control over it. The initial load time of the WordPress site is CRAZY slow… in the ~22 second range! After the initial load time I’m seeing anywhere from 5-9 seconds load time. So I thought I’d create a keepalive function to make a HTTP GET Request once every 4 minutes, since the app pool shuts down after 5 minutes of inactivity. At first I created a SUPER simple Python script to do this, and it worked well….. Until it didn’t. I wasn’t home for a couple of days and it stopped working. I was running it on a RPi at home. However, I didn’t have any kind of VPN setup, so I could login remotely to see what the issue was. I thought, heck, I’ll create a super quick Azure Function based on a timer to ping the site instead. That way I can see if there are issues online anywhere I have internet access and potentially fix the issue also.

I did that and it worked well. However, I started to notice some issues… The interval not kicking off every 4 mins like I set it up to do, and some communication service errors. The communication service error I attribute to potentially the sight being down at GoDaddy for maintenance or something similar. The not kicking off every four minutes??? I’m not sure what that issue might be attributed too, minus, maybe Azure maintenance?

I decided to replace all of this with a Azure Logic App. I started looking at an Azure Logic App, since I could easily create a workflow, that I could maintain. For example, I make the request every four minutes, if for some reason, I get a HTTP status code greater than or equal to 300 I can send myself a text message. In addition, it is really easy to hook it up to log to Azure Table Storage. Well there was a bit of trial and error to set it up, but I was able to figure it out in about 10 mins or so….

To insert into table storage the designer wants you to create valid json. The key for me was figuring out how to insert a GUID for the RowKey. See the syntax below:

{
"Body": "Body goes here",
"Headers": "@{outputs('HTTP')['headers']}",
"PartitionKey": "fsnKeepAlive",
"RowKey": "@{guid()}",
"StatusCode": "@outputs('HTTP')['statusCode']"
}

The @outputs sections were automatically created for me using the GUID, but I had to figure out that there was a guid function available in this context and the correct syntax.

In summary, the Azure Function gives a lot of control, but requires a but of coding. The Azure Logic App doesn’t require much “coding” AND provides a lot of features though the extensive list of integrations.

Leave a Reply

Your email address will not be published. Required fields are marked *