Azure App Service, Azure Blob, Azure Cloud, Cloud Computing

Azure storage data services types and How to store files in Azure Storage Account 2/2: Part 9

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.

9. Azure storage data services types and how to store files in azure storage account 2/2

Now we will do the same upload process programmatically in visual studio, we will only focus on the relevant code, and we do not discuss any coding best practices as it is out of scope of this series, it is left on user’s own discretion.

Install WindowsAzure.Storage nugget package

Open your visual studio if you have not opened it already and open the solution with which we are working in this series. Right click on solution | Manage Nugget Packages | click on Browse | search for azure storage. Install latest stable version in our case it is 8.7.0 and accept the license. By the time you read this post, Microsoft may have released new version, so do not worry about it as all the code will still work.

Figure 5 Install Windows AZURE Storage nugget package

Open you Index controller and the code should look like below; all you need to do is modify the highlighted with your credentials to make it work.

Figure 6 Change settings for storage account container

Now to get the Blob service endpoint Go to Storage Account | Blob Service | under Primary blob service endpoint you will have the URL, copy it.

Figure 7 Blob service endpoint

For storage account and keys Go to your storage account | Access keys, although storage account can be retrieved from main overview window, but this view will give you both account name and keys in one location. Please remember that whoever have these keys, will be able to manipulate almost anything in the storage account level so you do not want to give these keys to everyone. Azure provides us SAS (shared access service) which is robust and should be used to limit access in production environments. You also have option to regenerate keys, which will invalidate the previous keys and will provide you new keys.

Figure 8 Blob service Storage account and keys

Coding in Visual Studio

In first Index method, all we are doing is listing the blob files in the container images and making a dictionary, which have image name as key and image URL as value, and we are passing it to view using ViewBag.files.

Figure 9 Get all files in container

In post Index method, we are checking for file first, if exists then we are creating reference to the blob container with file name, but you could also use GUID for your blob name. Note that if a blob/file exists in the container with particular name and you use the same name to upload the file again then existing file will be overwritten. We are also using file stream to mitigate the need to save the file on disk first, you can of course implement your logic accordingly.

Figure 10 Insert Files in container

Full code for home controller is as below:

Now let us move to the view part, it is very simple, we just added the code for form, which will post to index method of home controller and is multipart that means will contain file as post response. We create an input with type file and a submit button. Make sure that your input file name is the same as you have mentioned the parameter to post Index file, otherwise you will not get the file in response.

Figure 11 File Upload code in MVC

We also included the code to display file name and picture along with it.

Figure 12 View all images code

Full code for Index View as below:

Now run the application locally and upload a picture, you will see that the filename is encoded in html friendly name as it have spaces in it and images are shown. There are two pictures as we upload first picture right after we created storage account and the other one is uploaded programmatically.

Figure 13 Complete view of file upload

You can also verify the image upload by going to images container in storage account.

Figure 14 Image uploaded to images container

This code tutorial is just starting point; you can play with it and use this code to modify according to your needs. I hope this being information for you.

Coming up next How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger

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

Azure storage data services types and how to store files in azure storage account 1/2 : Part 8

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

Azure Cloud

Creating Azure Database for MySQL and exporting the Data from My SQL In App to Azure Database for MySQL Server, Handling Security: Part 3

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
  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 Azure 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.

3.Creating Azure Database for MySQL and exporting the Data from My SQL In App to Azure Database for MySQL Server, Handling Security

At this point, your site is connected with WordPress.com now we are moving to part 3, which is Creating Azure Database for MySQL, and exporting the Data from My SQL in App to Azure Database for MySQL server, we will also handle security and will optimize with persistent connection.

Let us go to https://Portal.Azure.com/

Now go to All Resources and then click “Add” button, type “Azure MySQL” in search area and hit enter.

Search for Azure MySQL

1 Search for Azure MySQL

Right now we are interested in the first item, “Azure Database for MySQL (preview)” currently it is in preview but by the time you view this post, may be it is released to public as well.

Select Azure MySQL

2 Select Azure MySQL

Select “Azure Database for MySQL (preview)” and click on “Create”

Create Azure MySQL

3 Create Azure MySQL

At this point, add the Server Name, choose Resource Group, you can choose existing one, mention password and then for Pricing Tier choose “Basic” as this is our blog site it usually don’t need high throughput unless you are top blogger on internet, click “OK and complete the information and click “Create”

Enter Information for Azure MySQL instance, choose pricing tier

4 Enter Information for Azure MySQL instance, choose pricing tier

Job is submitted to Azure and it may take few minutes to complete.

Job is submitted to Azure

5 Job is submitted to Azure

Click on “Go to Resource”

Deployment completed.

6 Deployment completed.

Now we will disable the SSL enforce Status to false and we will add our IP Address and our Azure Web Service app’s IP Addresses, so that our WordPress site can access it. I will write an article on how to enable SSL in Azure MySQL so that it can communicate with our WordPress Site on encrypted channel, since it needs some changes in WordPress site. For now we are going to disable the SSL but we will add Connection security next.

Disabled the SSL for Database Server.

7 Disabled the SSL for Database Server.

Click on “Disabled” it will show like below, and click on “Save” button.

SSL Disable

8 SSL Disable

In mean while we will change our sites settings as below: Platform 64bit usually put more performance through put than 32 bit variant and Always On will keep your site in ram which will speed up the access time in case your WordPress site is not accessed for a long time and Click on “Save”

Optimizing Site Response Time

9 Optimizing Site Response Time

Now click on “Properties” under “settings” heading and copy all the IP address under “OUTBOUND IP ADDRESSES”, we will use these IP Address and add them in MySQL Server, so that our WordPress Site can access the Server without problem.

App Service IP Addresses

10 App Service IP Addresses

Now Add All the IP Address in “Connection Security” window and click on Save, use the Same IP Address for “START IP” and “END IP”, please make sure to add 1 IP Address at a time, since we have at least 4 or more IP Addresses copied from above window.

Connection Security

11 Connection Security

Your screen will look like below, and of course, IP Addresses will be different in your case, Add All IP Address and click on “Save” Button.

Insert IP Addresses of App Service

12 Insert IP Addresses of App Service

Now we are ready to move our database from MySQL in App to Azure MySQL. Go to “MySQL in APP” and click on export.

Export MySQL Database

13 Export MySQL Database

Now fill the information, if you do not know the Username and Database and Server, then you can always get this information from the MySQL Database instance.

Enter Credentials

14 Enter Credentials

Get Values for Server name and User ID

15 Get Values for Server name and User ID

For Database name, Click on “Manage” in “MySQL in APP”

Manage MySQL in App

16 Manage MySQL in App

A new window will open, if it prompt for login, please login. In our case, we have five databases listed as below: as we know that 4 out of 5 are MySQL databases (information_schema, mysql, performance_schema, sys) so this left us with one database “localdb”

PhpMyAdmin export database

17 PhpMyAdmin export database

Now fill out your “Export” form and click save

Export to New database instance

18 Export to New database instance

If you get below error then

Export Error

19 Export Error

Add below IP address range to allow all the IP address to connect with your database server and try again.

Enable IP Address for All

20 Enable IP Address for All

If for some reason you are unable to proceed then we can proceed for Export Option, Go to “Manage” in “MySQL in APP” and click on “Export” and click “Go”, save the resultant script to the local computer.

Exporting Databases

21 Exporting Databases

Now we will use Workbench to connect with MySQL database server, follow the link to download https://www.mysql.com/products/workbench/
Installing Workbench

22 Installing Workbench

There is an excellent documentation on Azure Docs, which explains how to connect to the MySQL server-using workbench

https://docs.microsoft.com/en-us/azure/mysql/connect-workbench

Now I assume you have downloaded and successfully connected to MySQL sever. Please follow below link navigate to “Data Import” heading, just connect to server, click option “Import from Disk” navigate to the file which we saved earlier in export part and click “Start Import”, everything supposed to work fine.

https://docs.microsoft.com/en-us/azure/mysql/concepts-migrate-import-export

Importing databases using Workbench

23 Importing databases using Workbench

Now is the part for connecting your WordPress to new MySQL server. Please proceed for following, Go to database server, “Connection strings” and then copy the connection string for “Web App” and modify it as per your MySQL Server credentials.

Database={your_database}; Data Source={your_databaseserver}; User Id={your_UserId}; Password={your_password}

Copy Connection string

24 Copy Connection string

Now go to “Application Settings”, add “Connection strings”, and add connection string with Name MYSQLCONNSTR and value with your modified Web App connection string and click “Save”

Saving Connection String in Application Settings

25 Saving Connection String in Application Settings

Now switch “MySQL in App” to “Off” and click on “Save”

Shutdown MySQL in App Instance

26 Shutdown MySQL in App Instance

Now Access you Site, it should be working fine. If you are getting any errors at this point, make sure that your credentials are correct.

Successfully did the Import

27 Successfully did the Import

Congratulations! You have successfully exported your MySQL Database to Your New Azure MySQL Instance.

After you are done, Please do not forget to remove the IP Address that we added to enable all to connect to over MySQL Server.

Delete Allow All IP Addresses
Delete Allow All IP Addresses

Upcoming next Creating Azure Storage Account and configuring WordPress to use Azure Storage to store media files.

Azure Cloud

Getting Azure Subscription, Creating App Service Plan and WordPress Web Service using My SQL In App: Part 1

[fusion_builder_container hundred_percent=”no” equal_height_columns=”no” menu_anchor=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” background_color=”” background_image=”” background_position=”center center” background_repeat=”no-repeat” fade=”no” background_parallax=”none” parallax_speed=”0.3″ video_mp4=”” video_webm=”” video_ogv=”” video_url=”” video_aspect_ratio=”16:9″ video_loop=”yes” video_mute=”yes” overlay_color=”” video_preview_image=”” border_size=”” border_color=”” border_style=”solid” padding_top=”” padding_bottom=”” padding_left=”” padding_right=””][fusion_builder_row][fusion_builder_column type=”1_1″ layout=”1_1″ background_position=”left top” background_color=”” border_size=”” border_color=”” border_style=”solid” border_position=”all” spacing=”yes” background_image=”” background_repeat=”no-repeat” padding_top=”” padding_right=”” padding_bottom=”” padding_left=”” margin_top=”0px” margin_bottom=”0px” class=”” id=”” animation_type=”” animation_speed=”0.3″ animation_direction=”left” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” center_content=”no” last=”no” min_height=”” hover_type=”none” link=””][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” class=”” id=””]

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
  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 Azure 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

1. Getting Azure Subscription, Creating App Service Plan and WordPress Web Service using My SQL In App

If you don’t have Azure Subscription Already then you can start for free with 200$ free credit to use in Azure https://azure.microsoft.com/en-us/free/

Create Your Azure Free Account Today

1 Create Your Azure Free Account Today

It requires you to have valid credit card information to proceed, please make sure to add valid phone number as it will send you the code to confirm your identity.

Please see following video if you need help in sign up process https://azure.microsoft.com/en-in/resources/videos/sign-up-for-microsoft-azure/

If you already have azure subscription then clicking on Start free will not do any good, and you will be greeted with below screen:

Looks like you already have a subscription

2 Looks like you already have a subscription

Once you complete your sign up process, go to azure portal https://portal.azure.com/

Your landing page will look something like below:

Azure Portal

3 Azure Portal

Now we are moving to create our very own WordPress website

Go to New
type WordPress hit enter

Search WordPress

4 Search WordPress

Choose WordPress by WordPress

Choose WordPress

5 Choose WordPress

Now click on create in next window

Create WordPress

6 Create WordPress

Now before choosing the name of the site we need to create a new App Service Plan, it is like a container for your applications, App Service Plan is what makes your WordPress Scalable, some App Service Plan let you scale automatically and others have manual option if you need more than one instance of your WordPress Site now make sure to choose the Location of the App Service Plan, which is near to you in my Case it is West Europe

Create App Service Plan

7 Create App Service Plan

Now after setting up the location, click on “Pricing tier”

Choose Pricing tier

8 Choose Pricing tier

Microsoft Recommends to choose at minimum S1 for any Production site, we are choosing S1, however you have option to create the site in free or shared environment as well

Choose Standard Edition

9 Choose Standard Edition

Now click “Select” and click “okay” button to select the app service plan, enter the website name, and remember this name should be globally unique across all .azurewebsites.net domain

Enter WordPress site name

10 Enter WordPress site name

Now this is time to choose our database provider, click on drop down arrow and select MySQL in App for now as Database Provider, it will use your WordPress site server resources to install local MySQL instance and use it for your WordPress Site.

Do not worry we will move this MySQL in App database to Azure Database for MySQL later on in this series

Choose MySQL Provider

11 Choose MySQL Provider

Choose MySQL in App

12 Choose MySQL in App

Once you click “Create” a Deployment job will be submitted to Azure, it can take few minutes to complete.

Deployment in progress

13 Deployment in progress

Once completed click on “Go to resources”

Deployment is succeeded

14 Deployment is succeeded

You can also choose click on “All resources” and then “wordpresssite1” in your case it will be the name of the site you entered earlier.

Go to resource

15 Go to resource

It will show below Screen, click on the URL and browse the site

Browse the WordPress site

16 Browse the WordPress site

Now after some loading, below screen will be shown, choose preferred language and click continue

Choose preferred language In WordPress

17 Choose preferred language In WordPress

Now fill out the foam, please make sure to put a valid email address and make sure to back up the credentials because you will use these to login to the site and click “Install WordPress”

Enter Credentials for WordPress

18 Enter Credentials for WordPress

After Installation is finished, login to the portal with the credentials used in installation screen, your screen should look like below

 WordPress Site is created on Azure

19 WordPress Site is created on Azure

Congratulations! Your site is up and running, upcoming next is how to connect it with WordPress.com and install Jet Pack.

Connecting Word Press website with WordPress.com and Installing and configuring Jet Pack

[/fusion_text][/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]