Azure App Service, Azure Blob, Azure Cloud, Azure Function, Azure Storage, Cloud Computing

How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 1/2: Part 10

I am putting together a series for people who are excited to bring Azure into their software development life cycle and use Azure cloud’s extensive services to their full potential.

In this series, I will cover as below:

  1. Getting Started with Azure Development, Create App Service Plan and Publish MVC project using Visual Studio
  2. Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK
  3. Remote debugging App Service using visual Studio, monitoring and configuring alerts
  4. Diagnostic logs, live stream, process explorer and KUDU
  5. How to use Azure SQL Database in Dot.net Applications
  6. How to use Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications
  7. How to use Visual Studio Team Service to do continuous Integration and continuous delivery
  8. Azure storage data services types and how to store files in azure storage account 1/2
  9. Azure storage data services types and how to store files in azure storage account 2/2
  10. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 1/2
  11. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 2/2

 

If you do not know where to start, please check my blog post, which covers detail about getting subscription and setting up. In this series, we assume that you already have active Azure subscription and Visual Studio 2013 or later installed on your system.

10. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 1/2

 

Azure Function is just a piece of code which will run upon a trigger or any supported events like, when adding something to container in Azure Storage, or on when new item is added in Queue, or you can schedule to run at a particular time. If you have used Web Jobs on Azure, then think of Azure Functions as an evolution of the web Jobs, which support integration with wide variety of Azure services, such as Azure cosmosDB, Azure EventHub, Azure Mobile Apps, Azure Storage and many more, which enable us to take action when a particular event is triggered. Azure Function is implementing the concept known server less computing and is used to build Nano-services.

Below is a list of supported triggers for Azure functions.

In this post, we will learn about Blob Trigger since we have learned to upload images as block blobs so it is obligatory to extend the functionality using Azure Functions. We will create a jpg version of uploaded png image on blob trigger and store it back in blob storage under same container, although there is an option to store the resultant image to another container as well.

Before we begin, let us take a look at pricing aspect of Azure functions, there are two basic offering, one is to use your existing App Service Plan to run functionApp in it, and another way is to calculate the number of times the function executes and they have a specific name for this called consumption plan. Since we already have App Service Plan so we are going to use it to execute our functions. For pricing information.

 

Remember that consumption plan have many advantages over App service plan, as you are allowed to run about 400,000 GB-s execution time for free and if your function is not being used you do not need to pay any extra cost and for some reason if your function have to run 10 million time or experience exponential growth, then Azure will manage the resources behind the scene to make sure there are enough resources to execute your function on demand. On the other hand in App Service Plan you need to pay for App service Plan even if there is no execution of your function and you will manage the scaling and performance of the App service plan.

Create Function App

Go to Azure Portal | Add new | Search Function | choose Function App | click create

 

Figure 1 Create Function App

Fill fields, we are going to use our existing App Service Plan. We are using existing storage account as well; these were created by us earlier in this series. Click create, it should not take much time to create function app.

 

Figure 2 Create Function App with App Service Plan

Once created, go to resource. You will find the main overview similar to below: azure is continuously evolving and by the time, you read this below screen may have been changed.

 

Figure 3 Overview Azure Function

Click on “Functions”, you will see that we do not have any function as of yet, click on new function.

 

Figure 4 function listing

Create Blob Trigger

You can see that there are multiple trigger choices we have and Azure is keep adding more as days passing by. We are going to use Blob Trigger and we will be using C# as programming language.

 

Figure 5 Create New function

Now click on C# link in the Blob Trigger tile.

 

Figure 6 C# Blog trigger

Modify function name:

 

Figure 7 Modify function name

If you run the function now, you will get error as “Exception binding parameter ‘myBlob’. Microsoft.WindowsAzure.Storage: The remote server returned an error: (404) Not Found”. You can see it in logs window at the bottom.

We are getting this error because we have not configured the container path and the blob path in test window on the right does not exists. Let us do that now.

 

Figure 8 Run Function

As the post is getting long, I am going to extend it to part 2.

We will continue building our FunctionApp in next part How to use Azure Functions and trigger on new Item addition in Azure Storage using BlobTrigger 2/2

Advertisements
Azure Cloud

How to install Application Insights in WordPress on Azure : Part 8

Are you looking to create your very own Scalable optimized WordPress Site/blog using Azure MySQL, Azure Storage and Azure CDN, then this post series is for you?

I have divided the series into below parts:

  1. Getting Azure Subscription, Creating App Service Plan and WordPress Web Service using My SQL In App
  2. Connecting Word Press website with WordPress.com and Installing and configuring Jet Pack
  3. Creating Azure Database for MySQL and exporting the Data from My SQL In App to Azure Database for MySQL Server, Handling Security and Optimizing with persistent connection
  4. Creating Azure Storage Account and configuring WordPress to use Azure Storage to store media files and Optimizing with persistent connection.
  5. Configuring Custom domain, SSL Certificates.
  6. Configuring CDN, configuring back up scheduling in azure and Auto Scaling
  7. How to use REDIS CACHE with WORDPRESS on Azure
  8. How to install application insights in WordPress on Azure

If you are not following along please check the previous part 1 first.

Application Insights is a good way to measure the performance of the Web site, also provide interactive data on Azure portal. Microsoft have also provided integration with Machine Learning. Application Insights have built in support for Asp.net development all you need to do is install the nugget package and enable it on the App Service and you are good to go.

The question arises how to enable Application Insights when you have WordPress Website on Azure, well this is what we answer today.

In order to configure Application Insights you need to do following:

  1. Install Application Insights plugin from WordPress Plugins
  2. Create Application Insights in Azure Portal or through App Service Application Insights
  3. Get and Configure the Instrumentation Key
  4. Access the website and look for details

  1. Install Application Insights plugin from WordPress Plugins, since I have installed and activated already so it is showing Active, for you it will show Install new.

Figure 1 Search for Application Insights in WordPress plugin

Now go to WordPress | Settings | Application insights; you can see that it requires Instrumentation Key.

Figure 2 Application Insights in WordPress

  1. Create Application Insights in Azure Portal or through App Service Application Insights

Go to Azure Portal, Click on new | search for Application Insights | select Application Insights | fill the form and choose Application Type as General and make sure that your application Insight location match the Location of your Service App and click on create. It may take some time to create it.

Figure 3 Application Insight Creation.

  1. Get and Configure the Instrumentation Key

Now to newly created application insight and in the overview window you will get the Instrumentation Key. Copy the Key and go to WordPress | Settings | Application insights and put the instrumentation key and click save.

Figure 4 Get Instrumentation Key

  1. Access the website and look for details

Now go to Application Insight Overview and see the traffic analytics. You may need to wait for some time to get the initial data.

Figure 5 Health of Application in Application Insights

For more information on Application Insights.

Azure Cloud

How to use Redis Cache with WordPress on Azure : Part 7

Are you looking to create your very own Scalable optimized WordPress Site/blog using Azure MySQL, Azure Storage and Azure CDN, then this post series is for you?

I have divided the series into below parts:

  1. Getting Azure Subscription, Creating App Service Plan and WordPress Web Service using My SQL In App
  2. Connecting Word Press website with WordPress.com and Installing and configuring Jet Pack
  3. Creating Azure Database for MySQL and exporting the Data from My SQL In App to Azure Database for MySQL Server, Handling Security and Optimizing with persistent connection
  4. Creating Azure Storage Account and configuring WordPress to use Azure Storage to store media files and Optimizing with persistent connection.
  5. Configuring Custom domain, SSL Certificates.
  6. Configuring CDN, configuring back up scheduling in azure and Auto Scaling
  7. How to use REDIS CACHE with WORDPRESS on Azure
  8. How to install application insights in WordPress on Azure

If you are not following along please check the previous part 1 first.

Now days it is very important to deliver your content as fast as you can deliver, in the world of performance Redis Cache have significantly gained the traction when it comes to quick response in milliseconds.

Since we are using Azure, it is very simple to use Azure Redis Cache with WordPress on azure. It start with creating an instance on your azure subscription and make sure to create it on same datacenter in which your App Service resides.

Go to Azure Portal click on add button, search for Redis Cache, fill the form and choose your Pricing tier according to your needs and click on create. It could take some time it to provision.

Figure 1 Create Azure Redis Cache for WordPress

Now go to your WordPress Dashboard and search for Redis Cache, you will find a Plugin with name Redis Object Cache, click on Install Now to install it. Once you are done, we need to install the plugin to our Azure App Service.

Figure 2 Install Redis Object Cache

Now go to below link and get the appropriate version of the plugin, in my case my PHP version is 7.1 you can see your by going to App Service | Application Settings | PHP Version

https://pecl.php.net/package/redis

Figure 3 get the plugin for Redis Object Cache

Now extract and Go to KUDU, App Service | Development Tools | Advanced Tool | GO, then click on Debug console | CMD and then click on site | siteextensions, you could see the path in CMD windows as D:homesitesiteextensions. Drag and drop the php_redis.dll here

Figure 4 Upload php_redis.dll to site extensions

Now create a folder in D:homesite as “ini” and create new file in it as “extensions.ini” and put this text in there and save

; Enable Extensions

extension=d:homesitesiteextensionsphp_redis.dll

Figure 5 Create ini folder with extensions.ini file

Figure 6 edit extensions.ini file

Now activate the Redis plugin from WordPress and after that go to WordPress | Settings | Redis and click diagnostics link. Right now, we have not modified wp-config.php file to put the required configuration so it will show Redis: Not Found. Let us do that now.

Figure 7 Redis Object Cache Diagnostics

Go back to KUDU, and navigate to d:homesitewwwroot and then edit wp-config.php and copy paste below code and do not forget to mention configuration highlighted as blod.

// Redis Cache plugin configuration

define(‘WP_REDIS_SCHEME’, ‘tcp’);

define(‘WP_REDIS_HOST’, ‘<redishost>‘);

define(‘WP_REDIS_PORT’, ‘6379’);

define(‘WP_REDIS_DATABASE’, ‘0’);

define(‘WP_REDIS_PASSWORD’, ‘<yourpass>‘);

define(‘WP_CACHE_KEY_SALT’, ‘<prefix>’);

Figure 8 Edit Wp-config.php

You can get the hostname and password from Redis Cache Overview as shown below. For password click on keys and use primary key.

Figure 9 Redis Cache Dashboard

Now click on Enable Object Cache, and wait for some time to enable it, after some time it will load the configuration and it will show you the status connected. If for some reason you it do not show connected then click on show diagnostics and enable disable object cache a few times.

Figure 10 Redis Cache is enabled.

Congratulations, you have successfully configured the Redis Cache with WordPress on Azure.

coming up next How to install application insights in WordPress on Azure