Azure API Management, Cloud Computing

How to setup your Open API in Azure API management : Part 3

 

In this post, we are discussing, how to Get Started with Azure API Management, how we can automate API subscription and management using Azure API Management.

This post is a part of the Azure Services series, in this series, we will discuss about Microsoft Cloud Application Architecture and common cloud computing patterns to make application resilient and scalable. We will be using Asp.net MVC as our framework for applicable examples and Azure as cloud services provider.

You can find all the Microsoft Azure Services; we have covered already at Azure series.

How to setup your Open API in Azure API management : Part 3

In previous post we discussed, how to create your own Open API in Dot.net Core using swagger and published on Azure App Service.

In this post we are going to configure our Open API in Azure API management.

We had published our Open API on Azure App service, we are going to use it to configure it with Azure API management. In order to proceed we need to have Full URL of the json file generated by the swagger, in our case it is as below:

http://azureapimanagementv1.azurewebsites.net/swagger/v1/swagger.json

you can click on the URL marked below and it will take you to the swagger.json file.

Let go to the Azure Portal | Azure API Management instance | under API management click APIs | Click on OpenAPI Specification | and copy the URL of the swagger.json file.

Now go to Azure API Over view | click on publisher portal | APIs | Import API | select From URL | choose Swagger | choose New API radio button | mention the suffix URL, this could be name of your service | and choose the scheme, we are going for https | click save.

Now if you go to Azure API Management Instance | APIs , you could see that our service is available there.

Let us assign it to ultimate product, in Products text box type unlimited | choose unlimited | save | verify the API is associated with product by going to unlimited product, as you can see our API is listed there.

Now to use this API, all we need to do is subscribe, which in turn will generate the subscription id that can be used to call the service methods. Since in this series we already subscribed to the unlimited product so we can use our primary key to call the methods of our service.

Go to Overview in Azure API Management | click on developer portal | sign in | Click APIs tab | click on Azure API management API | click try it | fill the field | send

By default, Delete method is select so beware of this when you test the API on production.

You should receive the successful response as below.

Let us consume this service, create a new Asp.net Core Web application with the name client.

We will use NSwagStudio to generate client side classes for the C#, download the tool from below Address:

https://github.com/RSuter/NSwag/wiki/NSwagStudio
First get the swagger URL for the API. Go to developer portal | API tab | Click on AzureAPIManagementV1 | click on API definition | choose Open API | then copy the URL

Once NSwagStudio is installed, open the tool, mention the URL and check CSharp Client and either you can click on Generate output button and get the CSharp client code which you can copy paste in visual studio or you can generate the file for you. I copied the path to my client project including the cs file name which will be generated. If you are getting error while generating, try to run the tool as administrator.

If you go to your visual studio the File is already added for you, if the file is not visible use the add existing item option to include it in the project.

Now let us use this to call the API. Open, Index.cshtml.cs in Get method type below code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

using Microsoft.AspNetCore.Mvc;

using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Client.Pages

{

public
class
IndexModel : PageModel

{

public
async
void OnGet()

{

System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient();

httpClient.DefaultRequestHeaders.Add(“Ocp-Apim-Subscription-Key”, “ba210977b3374feb89caafefe28ba78d”);

MyNamespace.Client client = new MyNamespace.Client(httpClient);

System.Collections.ObjectModel.ObservableCollection<string> x = await client.ApiValuesGetAsync();

}

}

}

As you can see we need to include the Ocp-Apim-Subscription-Key
in default header.

If you debug you will get the proper response.

Azure Cloud, Azure Cloud Services, Cloud Computing, Cloud development Patterns

Microsoft Azure cloud Application Development architecture and common cloud computing patterns to make application resilient and scalable

In this series, we will discuss about Microsoft Cloud Application Architecture and common cloud computing patterns to make application resilient and scalable.

We will be using Asp.net MVC as our framework for applicable examples and Azure as cloud services provider.

If you are new to azure development, check out Getting Started Azure development guide.

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.

Since we are using Microsoft Azure cloud as cloud services provider, let us discuss the type of services azure provide us. First, we will discuss usual broad categories of services and then we will move to Azure specific services types. We can divide Microsoft Azure services into 3 broad categories such as below:

  1. Infrastructure as a Service
  2. Platform as a Service
  3. Software as a Service

Infrastructure as a Service

This is the basic providing of any cloud services provider; it is renting the IT Infrastructure for your use, it includes compute resources such as VMs for windows, Linux etc. Storage to store data, network resources such VPN etc. You have full control over the resources and it is your responsibility to apply the patches and do maintenance, although Microsoft provide you Service Level Agreement and guarantees the up time of the resources. You will mostly pay for resources you use with respect to time or number of unit consumed, and is usually called Pay as you go model, which we will discuss in detail later on in this series.

All these resources enable you to do what we call as lift and shift migration, you only need is to migrate all resources to cloud as it is. Infrastructure is the main building block and enable even cloud providers to provide as Paas, Saas and other services, which we look at next.

Platform as a Service

Every Cloud resource provider services, which enable developers to quickly deliver services/solutions  without need to manage the underlying infrastructure such as VM, storage, network. These providing are usually can be acquired on demand and can scale as your solution demand more resources. Payment model for these is the same as pay as you go or some time unit of consumption.

Software as a Service

In software as a service, usually vendors use cloud-computing provider’s services to develop solutions and expose their services as software. End users (you) of services do not need to worry about anything related to under lying infrastructure or to manage any resources, users just use the services over the internet using browser and payment method is usually subscription based. Office365 is a good example of Saas.

Now once we have passed the board categories discussion, let us move to exciting part of the services available to us on Microsoft Azure.

Microsoft Azure Cloud Services

Microsoft Azure Cloud provide a whole bunch of Cloud Services, some are listed below, and as the list is keep growing, we will keep adding them to the list.

Compute Networking Storage Web + Mobile Containers Databases Analytics
Virtual Machine Content Delivery Network StorSimple App Service App Service SQL Database HDInsight
Functions Azure DNS Data Lake Store Notification Hubs Container Registry SQL Data warehouse Apache Strom for HDInsight
Container Instances Traffic Manager Disk Storage Logic Apps Service Fabric SQL Server Stretch Database SQL Data Warehouse
Virtual Machine Scale Set VPN Gateway Queue Storage Live and On-Demand Streaming Batch Azure Database for PostgreSQL Event Hubs
Cloud Services Azure DDoS Protection Backup Content Protection Container Instances Azure Database Migration Service Log Analytics
Windows Virtual Machine ExpressRoute Site recovery Web Apps Azure Container Service (AKS) Azure Cosmos DB Data Lake Store
SAP Hana on Azure Large Instances Virtual Network Blob storage API Apps Redis Cache Azure Analysis Services
Batch Load Balancer Managed Disks API Management Table Storage Power BI Embedded
Service Fabric Application Gateway File Storage Media Services Azure Database for MySQL Apache Spark for Azure HDInsight
Azure Container Service (AKS) Network watcher Azure Search R Server for HDInsight
Linux Virtual Machines Encoding Stream Analytics
SQL Server on Virtual Machines Azure Media Player Data Factory
Azure Media Indexer Data Catalog
Mobile Apps Data Lake Analytics
Media Analytics Azure databricks
Content Delivery Network
AI + Machine Learning   Internet of things Integration Services Security and Identity Developer Tools Management Tools  
Machine Learning Studio Cognitive Services Azure Cosmos DB StorSimple Azure Active Directory Visual Studio Team Services Backup Automation and Control
Azure Bot Service Text Analytics API Machine Learning Studio Data Factory Azure Information Protection Application Insights Application Insights Network Watcher
Academic Knowledge API Computer Vision API Event Hubs Data Catalog Key Vault Hockey App Scheduler Microsoft Azure Portal
Content Moderator Emotion API Logic Apps Logic Apps Security Center API Management Log Analytics Cloud shell
Face API Bing Speech API Time Series Insights API Management Multi-Factor Authentication Azure DevTest Labs Azure Monitor Azure Policy
Web Language Model API Language Understanding ( LUIS ) IoT Edge Service Bus Azure Active Directory Domain Services Visual Studio App Centre Protection and Recovery Azure Management Applications
Speaker Recognition API Custom Speech Service IoT Hub SQL Server Stretch Database Azure Active Directory B2C Insight and Analytics
Bing Auto suggest Bing Spell Check API Stream Analytics Event Grid Azure Service health
Translator Speech API Translator Text API Notification Hubs Azure Resource Manager
Bing Custom Search API Bing Entity Search API IoT Suite Azure Mobile App
Bing Web Search API Bing Video Search API Event Grid Cost Management
Bing Image Search API Bing News Search API Azure Location Based Services Azure Migrate
Custom Decision Services QnA Marker API Blockchain Site Recovery
Knowledge Exploration Service Entity Linking Intelligence API Azure Advisor
Microsoft Genomics Video Indexer Automation
Linguistic Analysis API Azure Batch AI Traffic Manager
Custom Vision Service Machine Learning Services Security and Compliance

I know it is long list; and some items are duplicated as well under some headings, unbelievably, we are going to cover every one of the items listed above, and will discuss common cloud patterns for each item. As we go, we will keep adding the Icons for each discussed item, when a relative item’s post published on this site.

We are going to group some items in an implementation to cover real world scenarios and best practices as well as common cloud patterns while development, related source code will be available through GitHub.

This will be long and exciting journey, I hope you are ready, because we are about to get started.

Stay Tuned.

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

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