<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Azure Function &#8211; Sibeesh Passion</title>
	<atom:link href="https://sibeeshpassion.com/tag/azure-function/feed/" rel="self" type="application/rss+xml" />
	<link>https://sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Tue, 13 May 2025 20:06:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>Azure Function &#8211; Sibeesh Passion</title>
	<link>https://sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Linux Azure Function Isolated Dot Net 9 YAML Template Deployment</title>
		<link>https://sibeeshpassion.com/linux-azure-function-isolated-dot-net-9-yaml-template-deployment/</link>
					<comments>https://sibeeshpassion.com/linux-azure-function-isolated-dot-net-9-yaml-template-deployment/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Sun, 27 Apr 2025 11:05:56 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[azure function release pipeline]]></category>
		<category><![CDATA[azure function worker process]]></category>
		<category><![CDATA[azure function yaml template and release]]></category>
		<category><![CDATA[dot net 9]]></category>
		<category><![CDATA[dotnet-isolated]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=14697</guid>

					<description><![CDATA[Introduction In this post, let&#8217;s see how we can deploy a dot net 9 isolated runtime model project to a Linux based Azure function. Prerequisites Creating the hosting plan It is not mandatory to create a hosting plan, as the resource will be auto created when you create the function, however it is recommended to create one as you can define your naming strategies and more controls. Here we are choosing the consumption plan. You can learn more about the hosting options Azure provides here. Below is the ARM template to create the consumption hosting plan. Creating the Azure function [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h1 class="wp-block-heading">Introduction</h1>



<p>In this post, let&#8217;s see how we can deploy a dot net 9 isolated runtime model project to a Linux based Azure function.</p>



<h1 class="wp-block-heading"><strong>Prerequisites</strong></h1>



<h2 class="wp-block-heading"><strong>Creating the hosting plan</strong></h2>



<p>It is not mandatory to create a hosting plan, as the resource will be auto created when you create the function, however it is recommended to create one as you can define your naming strategies and more controls. Here we are choosing the consumption plan. You can learn more about the hosting options Azure provides <a href="https://learn.microsoft.com/en-us/azure/azure-functions/functions-scale">here</a>. Below is the ARM template to create the consumption hosting plan.</p>



<pre class="wp-block-code"><code>{
    "type": "Microsoft.Web/serverfarms",
    "apiVersion": "2024-04-01",
    "name": "&#91;parameters('funcAppServerFarmName')]",
    "location": "&#91;parameters('funcAppLocation')]",
    "kind": "functionapp",
    "sku": {
        "name": "Y1",
        "tier": "Dynamic"
    },
    "properties": {
        "computeMode": "Dynamic",
        "reserved": true
    }
}</code></pre>



<p><strong>Creating the Azure function</strong></p>



<p>Below is the ARM template to create the Azure function.</p>



<pre class="wp-block-code"><code>{
    "type": "Microsoft.Web/sites",
    "apiVersion": "2024-04-01",
    "name": "&#91;parameters('FuncName')]",
    "location": "&#91;parameters('funcAppLocation')]",
    "kind": "functionapp,linux",
    "identity": {
        "type": "SystemAssigned"
    },
    "properties": {
        "reserved": true,
        "alwaysOn": true,
        "serverFarmId": "&#91;resourceId('Microsoft.Web/serverfarms', parameters('funcAppServerFarmName'))]",
        "linuxFxVersion": "DOTNET-ISOLATED|9.0",
        "siteConfig": {
            "linuxFxVersion": "DOTNET-ISOLATED|9.0",
            "appSettings": &#91;
                {
                    "name": "AzureWebJobsStorage",
                    "value": "&#91;format('DefaultEndpointsProtocol=https;AccountName={0};EndpointSuffix={1};AccountKey={2}', parameters('StorageName'), environment().suffixes.storage, listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('StorageName')), '2022-05-01').keys&#91;0].value)]"
                },
                {
                    "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                    "value": "&#91;reference(resourceId('Microsoft.Insights/components', parameters('InsightsComponentName')), '2020-02-02').InstrumentationKey]"
                },
                {
                    "name": "FUNCTIONS_EXTENSION_VERSION",
                    "value": "~4"
                },
                {
                    "name": "FUNCTIONS_WORKER_RUNTIME",
                    "value": "dotnet-isolated"
                },
                {
                    "name": "linuxFxVersion",
                    "value": "DOTNET-ISOLATED|9.0"
                },
                {
                    "name": "WEBSITE_USE_PLACEHOLDER_DOTNETISOLATED",
                    "value": "1"
                },
                {
                    "name": "CosmosConnectionString",
                    "value": "&#91;concat('@Microsoft.KeyVault(SecretUri=', 'https://',parameters('KeyVaultName'),'.vault.azure.net/secrets/CosmosConnectionString)')]"
                }
            ],
            "minTlsVersion": "1.3"
        },
        "runtime": {
            "name": "dotnet-isolated"
        },
        "httpsOnly": true
    },
    "dependsOn": &#91;
        "&#91;resourceId('Microsoft.Insights/components', parameters('InsightsComponentName'))]",
        "&#91;resourceId('Microsoft.Web/serverfarms', parameters('funcAppServerFarmName'))]",
        "&#91;resourceId('Microsoft.Storage/storageAccounts', parameters('StorageName'))]"
    ]
}</code></pre>



<p>Please make sure to set the values linuxFxVersion, WEBSITE_USE_PLACEHOLDER_DOTNETISOLATED or you may get the error below when you deploy your code to the Azure function.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><em>Failed to sync triggers for function app &#8216;funcsintest03&#8217;. Error: BadRequest &#8211; Encountered an error (BadGateway) from host runtime. (CODE: 400)</em></p>
</blockquote>



<p>I have a detailed post on the error <a href="https://stackoverflow.com/a/79594377/5550507">here on Stack Overflow</a>. Here is a doc on <a href="https://learn.microsoft.com/en-us/azure/azure-functions/functions-infrastructure-as-code?pivots=consumption-plan&amp;tabs=json%2Clinux%2Cdevops">Automate resource deployment for your function app in Azure Functions</a>.</p>



<h1 class="wp-block-heading">Create Azure function application</h1>



<p>You can easily create the Azure function using the <a href="https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-your-first-function-visual-studio">Visual Studio by following this post</a>. Please be noted that for my Azure function I am choosing my function to run in an isolated worker process to get the benefits like standard dependency injection, you can read more on this <a href="https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide?tabs=hostbuilder%2Clinux">here</a>.</p>



<h1 class="wp-block-heading">Create the Azure DevOps pipelines</h1>



<p>Before we create the pipelines, let’s create the template YAML with the file name as func-template.yml so that we can use it for all of our environments like Dev, Test, Prod etc.</p>



<pre class="wp-block-code"><code>parameters:
  - name: azureSubscriptionServiceConnection
    type: string
  - name: functionAppName
    type: string
  - name: stageName
    type: string

stages:
  - stage: ${{ parameters.stageName }}_Stage
    displayName: Release stage ${{ parameters.stageName }}
    jobs:
      - job: ${{ parameters.stageName }}_Release
        displayName: ${{ parameters.stageName }}_Release
        pool:
          vmImage: "ubuntu-latest"
        steps:
          # Download an artifact named 'WebApp' to 'bin' in $(Build.SourcesDirectory)
          - task: DownloadPipelineArtifact@2
            inputs:
              artifactName: "drop"
              targetPath: $(Build.SourcesDirectory)/bin
          - task: AzureFunctionApp@2 # Add this at the end of your file
            inputs:
              azureSubscription: ${{ parameters.azureSubscriptionServiceConnection }}
              appType: functionAppLinux # This specifies a Linux-based function app
              #isFlexConsumption: true # Uncomment this line if you are deploying to a Flex Consumption app
              appName: ${{ parameters.functionAppName }}
              package: $(Build.SourcesDirectory)/bin/*.zip
              deploymentMethod: "zipDeploy" # 'auto' | 'zipDeploy' | 'runFromPackage'. Required. Deployment method. Default: auto.
              #Uncomment the next lines to deploy to a deployment slot
              #Note that deployment slots is not supported for Linux Dynamic SKU
              #deployToSlotOrASE: true
              #resourceGroupName: '&lt;RESOURCE_GROUP>'
              #slotName: '&lt;SLOT_NAME>'
              runtimeStack: 'DOTNET-ISOLATED|9.0'
</code></pre>



<p>Here we use the task AzureFunctionApp@2 task, you can learn more about that task <a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/azure-function-app-v2?view=azure-pipelines">here</a>. Next, create a YAML file func-template.yml with the contents below.</p>



<pre class="wp-block-code"><code>trigger:
  - main
stages:
  - stage: Build
    displayName: Build and push stage
    jobs:
      - job: Build
        displayName: Build
        pool:
          vmImage: "ubuntu-latest"
        steps:
          - task: UseDotNet@2
            inputs:
              packageType: "sdk"
              version: "9.0.x" # .NET 9 preview/stable depending on your needs
              installationPath: $(Agent.ToolsDirectory)/dotnet
          - checkout: self
          - script: |
              dotnet restore
              dotnet build --configuration Release
          - task: DotNetCoreCLI@2
            inputs:
              command: publish
              arguments: "--configuration Release --output publish_output"
              projects: "$(System.DefaultWorkingDirectory)/MyFunc.Func/MyFunc.Func.csproj"
              publishWebProjects: false
              modifyOutputPath: false
              zipAfterPublish: false
          - task: ArchiveFiles@2
            displayName: "Archive files"
            inputs:
              rootFolderOrFile: "$(System.DefaultWorkingDirectory)/publish_output"
              includeRootFolder: false
              archiveFile: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip"
          - task: PublishBuildArtifacts@1
            inputs:
              PathtoPublish: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip"
              artifactName: "drop"

  - template: func-template.yml
    parameters:
      azureSubscriptionServiceConnection: "MyFuncdevmi"
      functionAppName: "MyFuncfuncsindev03"
      stageName: "DEV"
  - template: func-template.yml
    parameters:
      azureSubscriptionServiceConnection: "MyFunctestmi"
      functionAppName: "MyFuncfuncsintest03"
      stageName: "TEST"
</code></pre>



<p>In the above YAML file, my function project name is MyFunc and I am using the MyFuncdevmi as the service connection to deploy the Azure function to the DEV environment MyFuncfuncsindev03 and MyFunctestmi to deploy to my TEST environment MyFuncfuncsintest03.</p>



<p>I am using managed identity to create those service connection. You can create a managed identity using the ARM template below.</p>



<pre class="wp-block-code"><code>{
    "type": "Microsoft.ManagedIdentity/userAssignedIdentities",
    "apiVersion": "2024-11-30",
    "name": "&#91;parameters('managedIdentityName')]",
    "location": "&#91;parameters('location')]",
    "tags": {
        "{customized property}": "string"
    }
}&nbsp; &nbsp; &nbsp;</code></pre>



<p>You can follow this doc to create the <a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/library/connect-to-azure?view=azure-devops">service connection using the managed identity</a>.</p>



<h1 class="wp-block-heading">Create the pipeline using the YAMLs created</h1>



<p>Go to the Pipeline menu and click on New pipeline button. Select your Azure DevOps repository and click on the option Existing Azure Pipelines YAML file. </p>



<figure class="wp-block-image size-large"><a href="/wp-content/uploads/2025/04/image.png"><img fetchpriority="high" decoding="async" width="1024" height="434" src="/wp-content/uploads/2025/04/image-1024x434.png" alt="" class="wp-image-14699" srcset="/wp-content/uploads/2025/04/image-1024x434.png 1024w, /wp-content/uploads/2025/04/image-300x127.png 300w, /wp-content/uploads/2025/04/image-768x325.png 768w, /wp-content/uploads/2025/04/image-1536x651.png 1536w, /wp-content/uploads/2025/04/image-2048x867.png 2048w, /wp-content/uploads/2025/04/image-400x169.png 400w, /wp-content/uploads/2025/04/image-1417x600.png 1417w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure>



<p>Choose the path to your release pipeline YAML file, not the template YAML file, and run your pipeline. If your pipeline is successful, you should be able to see the output as below.</p>



<figure class="wp-block-image size-large"><a href="/wp-content/uploads/2025/04/image-3.png"><img decoding="async" width="1024" height="364" src="/wp-content/uploads/2025/04/image-3-1024x364.png" alt="" class="wp-image-14704" srcset="/wp-content/uploads/2025/04/image-3-1024x364.png 1024w, /wp-content/uploads/2025/04/image-3-300x107.png 300w, /wp-content/uploads/2025/04/image-3-768x273.png 768w, /wp-content/uploads/2025/04/image-3-1536x546.png 1536w, /wp-content/uploads/2025/04/image-3-2048x728.png 2048w, /wp-content/uploads/2025/04/image-3-400x142.png 400w, /wp-content/uploads/2025/04/image-3-1689x600.png 1689w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure>



<figure class="wp-block-image size-large"><a href="/wp-content/uploads/2025/04/image-1.png"><img decoding="async" width="1024" height="270" src="/wp-content/uploads/2025/04/image-1-1024x270.png" alt="" class="wp-image-14700" srcset="/wp-content/uploads/2025/04/image-1-1024x270.png 1024w, /wp-content/uploads/2025/04/image-1-300x79.png 300w, /wp-content/uploads/2025/04/image-1-768x202.png 768w, /wp-content/uploads/2025/04/image-1-1536x404.png 1536w, /wp-content/uploads/2025/04/image-1-2048x539.png 2048w, /wp-content/uploads/2025/04/image-1-400x105.png 400w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure>



<h1 class="wp-block-heading">Conclusion</h1>



<p>In this post we have learned how to,</p>



<ul class="wp-block-list">
<li>create the Azure function and consumption hosting plan with dotnet isolated worker process</li>



<li>create the temple for the deploying the Azure function</li>



<li>create the release YAML using the template file</li>
</ul>



<h1 class="wp-block-heading">About the Author</h1>



<p>I am yet another developer who is passionate about writing and sharing knowledge. I have written more than 500 blogs on my&nbsp;<a rel="noreferrer noopener" href="https://sibeeshpassion.com/" target="_blank">blog</a>. If you like this content, consider following me here,</p>



<ul class="wp-block-list">
<li><a href="https://github.com/SibeeshVenu">GitHub</a></li>



<li><a href="https://medium.com/@sibeeshvenu">medium</a></li>



<li><a href="https://twitter.com/sibeeshvenu">Twitter</a></li>
</ul>



<h1 class="wp-block-heading">Your turn. What do you think?</h1>



<p>Thanks a lot for reading. Did I miss anything that you may think is needed in this article? Could you find this post useful? Kindly do not forget to share your feedback.</p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/linux-azure-function-isolated-dot-net-9-yaml-template-deployment/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Show Recent Blog Posts in GitHub ReadMe using Azure Function</title>
		<link>https://sibeeshpassion.com/show-recent-blog-posts-in-github-readme-using-azure-function/</link>
					<comments>https://sibeeshpassion.com/show-recent-blog-posts-in-github-readme-using-azure-function/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 20 Jul 2020 18:30:34 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[azure function to get latest blog feed]]></category>
		<category><![CDATA[custom github home page]]></category>
		<category><![CDATA[dynamic image with dynamic text writing c#]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[Github readme]]></category>
		<category><![CDATA[SixLabors.ImageSharp]]></category>
		<category><![CDATA[write text on image programatically]]></category>
		<guid isPermaLink="false">http://sibeeshpassion.com/?p=14165</guid>

					<description><![CDATA[I am showing the image of the titles of my recent 5 blog posts on my GitHub home page automatically. I did it using the Azure Function, Azure is Love, right?]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Introduction</h2>



<p>GitHub recently introduced an option to customize our profile by giving a separate magical repository. This repository name should be the same as your username, for example, https://github.com/SibeeshVenu/sibeeshvenu. This is how you can find this secret repository. </p>



<figure class="wp-block-image size-large"><img decoding="async" width="650" height="177" src="/wp-content/uploads/2020/07/Secret-repository.png" alt="" class="wp-image-14167" srcset="/wp-content/uploads/2020/07/Secret-repository.png 650w, /wp-content/uploads/2020/07/Secret-repository-300x82.png 300w, /wp-content/uploads/2020/07/Secret-repository-425x116.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>GitHub secret repository</figcaption></figure>



<p>Now opens an endless opportunity that you can do to your GitHub home page, for example, I am showing the image of the titles of my recent 5 blog posts on my home page automatically. I did it using the Azure Function which will return the image and all I had to do in this repository, was to use it. Overall it was fun. </p>



<figure class="wp-block-image size-large"><img decoding="async" width="650" height="302" src="/wp-content/uploads/2020/07/Custom-github-home-page.png" alt="" class="wp-image-14168" srcset="/wp-content/uploads/2020/07/Custom-github-home-page.png 650w, /wp-content/uploads/2020/07/Custom-github-home-page-300x139.png 300w, /wp-content/uploads/2020/07/Custom-github-home-page-425x197.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Custom GitHub home page</figcaption></figure>



<p>Here in this post, we will see how we can develop an Azure Function solution that returns the above-mentioned image.</p>



<h2 class="wp-block-heading">Develop an Azure function</h2>



<p>The first thing that you need to do, is to create a new Azure Function. Go to your Azure portal, and search for Azure Function, the creation process is the same and easy as we create any other Azure resources. If you are interested, you can check out my articles related to <a href="https://sibeeshpassion.com/tag/azure-function/" target="_blank" rel="noreferrer noopener">Azure Function here</a>.</p>



<p>Once you create the Azure function, you are good to go and develop an Azure function application in Visual Studio. Here I am using Visual Studio 2019. </p>



<figure class="wp-block-image size-large"><img decoding="async" width="650" height="702" src="/wp-content/uploads/2020/07/Create-Azure-function-using-visual-studio.jpg" alt="" class="wp-image-14169" srcset="/wp-content/uploads/2020/07/Create-Azure-function-using-visual-studio.jpg 650w, /wp-content/uploads/2020/07/Create-Azure-function-using-visual-studio-278x300.jpg 278w, /wp-content/uploads/2020/07/Create-Azure-function-using-visual-studio-425x459.jpg 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Create Azure function using visual studio</figcaption></figure>



<p>We are going to create an HttpTrigger Azure function, so make sure you select that option on the next screen. If you need a basic introduction about the HttpTrigger Azure function, you can read this post <a href="https://sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/#play-with-azure-function" target="_blank" rel="noreferrer noopener">here</a>. I named my function as GetLatestPosts, and feel free to give any name you wish. This Azure function has the preceding jobs to do.</p>



<ol class="wp-block-list"><li>Get the latest posts details from the feed of my blog</li><li>Create an image with the feed data</li><li>Send back the image as a stream</li></ol>



<h3 class="wp-block-heading">Get the latest posts details from the feed</h3>



<p>You can usually get the feed data by going to {yoursitelink}/feed. For example, I can get my feed data by going to <a href="https://sibeeshpassion.com/feed/">https://sibeeshpassion.com/feed/</a>. So in our function, we will get this data using an XmlReader and Deserialize the same using SyndicationFeed. Please be noted that the Syndication namespace is part of the System.ServiceModel and you should install the Nuget package System.ServiceModel.Syndication. Preceding is the function to retrieve the latest 5 blog posts details.</p>



<script src="https://gist.github.com/SibeeshVenu/d994dd2c5b013333943dae3b52f1e961.js"></script>



<h3 class="wp-block-heading">Create an image with titles </h3>



<p>Now we need a function to generate an image and write the blog posts title to that image dynamically. To do this, we are using the Nuget package called  SixLabors.ImageSharp. Feel free to use any packages you like, the only thing that matters is that we need an image with the blog posts titles. The SixLabors.ImageSharp is indeed an amazing library, I can recommend you to give it a try. This is how your Nuget package installed window should look like now.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="536" src="/wp-content/uploads/2020/07/Required-Nuget-packages-1024x536.jpg" alt="" class="wp-image-14170" srcset="/wp-content/uploads/2020/07/Required-Nuget-packages-1024x536.jpg 1024w, /wp-content/uploads/2020/07/Required-Nuget-packages-300x157.jpg 300w, /wp-content/uploads/2020/07/Required-Nuget-packages-768x402.jpg 768w, /wp-content/uploads/2020/07/Required-Nuget-packages-425x222.jpg 425w, /wp-content/uploads/2020/07/Required-Nuget-packages.jpg 1495w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Required Nuget packages</figcaption></figure>



<p>Now we cna write the function as preceding.</p>



<script src="https://gist.github.com/SibeeshVenu/33b6e46ead886df91d533d9fe9c10ca2.js"></script>



<p>As you can see that there is a Configuration class, from where we take all the configurations. Let&#8217; write that now. You can also use Environment variables here, I may update my repository in the coming days.</p>



<script src="https://gist.github.com/SibeeshVenu/a5cbc95db906783e8b8319cb5f2d0f80.js"></script>



<p>The SixLabors.ImageSharp has an inbuilt extension function called ToBase64String, which will return the image as base64 string. Did you notice that we are using another extension method here, &#8220;ApplyScalingWaterMark&#8221;? Let&#8217;s create a class for our Extension methods so that it will be handy in the future. </p>



<script src="https://gist.github.com/SibeeshVenu/44f2c33e3294be08ba28b8c975712ad5.js"></script>



<h3 class="wp-block-heading">Azure function to return a stream</h3>



<p>As all the supporting methods are ready, let us write our main function, the ultimate job of this function is to convert the base64 string to a stream and return the stream. As simple as that. </p>



<script src="https://gist.github.com/SibeeshVenu/895d90a8d624d2ff663e8147e44a6b99.js"></script>



<p>Once your Azure function is ready, please remember to publish the same to Azure. To publish your Azure Function app, just right click on your project and click Publish and then set up your publish target by choosing the existing Azure Function App, remember we have created one earlier?&nbsp;</p>



<h2 class="wp-block-heading">Develop secret GitHub readme repository</h2>



<p>Here I am assuming that you already created your secret repository. And if yes, you can update the &#8220;readme&#8221; content as follows. Please remember this is just a sample, you can update as you wish.</p>



<script src="https://gist.github.com/SibeeshVenu/cab2f65acc9feb46ce991788118b4c31.js"></script>



<p>Boom!. We did it. Now go to your GitHub home page, and I am sure that you will love your new beautiful, detailed home page.</p>



<h2 class="wp-block-heading">Update</h2>



<p>As GitHub has a very low timeout, sometimes the image created was not showing in my profile. Thus, I had to change the mechanism. I changed my Azure function to a time trigger function that runs every hour and the main functionality of this function now is to generate the image and upload to the Azure blob storage. Now I can directly get the blob image URL in the Readme file. No more timeout issues. Preceding is the codes of the new Azure function. You can also see this in the Dev branch of the repository.</p>



<script src="https://gist.github.com/SibeeshVenu/026e07fe611f82c568658c1cfbbb1e08.js"></script>



<h2 class="wp-block-heading">Source Code</h2>



<p>Please feel free to check out the repositories here.</p>



<ul class="wp-block-list"><li><a href="https://github.com/SibeeshVenu/GitHubFuncs">https://github.com/SibeeshVenu/GitHubFuncs</a></li><li><a href="https://github.com/SibeeshVenu/sibeeshvenu">https://github.com/SibeeshVenu/sibeeshvenu</a></li></ul>



<h2 class="wp-block-heading">About the Author</h2>



<p>I am yet another developer who is passionate about writing and video creation. I have written close to 500 blogs on my&nbsp;<a href="https://sibeeshpassion.com/" target="_blank" rel="noreferrer noopener">blog</a>. And I upload videos on my YouTube channels&nbsp;<a href="https://www.youtube.com/njanorumalayali" target="_blank" rel="noreferrer noopener">Njan Oru Malayali</a>&nbsp;and&nbsp;<a href="https://www.youtube.com/SibeeshPassion" target="_blank" rel="noreferrer noopener">Sibeesh Passion</a>. Please feel free to follow me.</p>



<ul class="wp-block-list"><li><a href="https://github.com/SibeeshVenu">GitHub</a></li><li><a href="https://medium.com/@sibeeshvenu">medium</a></li><li><a href="https://twitter.com/sibeeshvenu">Twitter</a></li></ul>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post useful? Kindly do not forget to share your feedback.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/show-recent-blog-posts-in-github-readme-using-azure-function/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Create Custom Web Apps for Microsoft Teams Using Azure Function, Node Js</title>
		<link>https://sibeeshpassion.com/create-custom-web-apps-for-microsoft-teams-using-azure-function-node-js/</link>
					<comments>https://sibeeshpassion.com/create-custom-web-apps-for-microsoft-teams-using-azure-function-node-js/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 23 Jun 2020 11:51:03 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[develop custom apps for microsoft teams]]></category>
		<category><![CDATA[javascript sdk for teams]]></category>
		<category><![CDATA[load static website using azure function]]></category>
		<category><![CDATA[microsoft teams app with vuejs]]></category>
		<category><![CDATA[Office 365]]></category>
		<category><![CDATA[yeoman generator vuejs]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=14121</guid>

					<description><![CDATA[Do you know that we can always develop our own web apps and integrate the same to our Microsoft Teams? That is exactly what we are going to do in this blog.]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>The popularity of Microsoft Teams is getting increased day by day, thus the new requirements. Do you know that we can always develop our own web apps and integrate the same to our Microsoft Teams? That is exactly what we are going to do in this blog. Let&#8217;s start then.</p>



<h2 class="wp-block-heading">Background</h2>



<p>My plan was to create a web application in Vuejs with Nodejs, and convert the same to Microsoft Team&#8217;s web application so that my Team members can use it. There is a generator that helps you create a basic application with some default functionality, but that will support only Angular and react for now (the time that I write this article). </p>



<figure class="wp-block-image size-large"><img decoding="async" width="948" height="883" src="https://sibeeshpassion.com/wp-content/uploads/2020/06/yo-office.png" alt="" class="wp-image-14122" srcset="/wp-content/uploads/2020/06/yo-office.png 948w, /wp-content/uploads/2020/06/yo-office-300x279.png 300w, /wp-content/uploads/2020/06/yo-office-768x715.png 768w, /wp-content/uploads/2020/06/yo-office-425x396.png 425w" sizes="(max-width: 948px) 100vw, 948px" /><figcaption>yo office generator </figcaption></figure>



<p>You should also keep in mind that you will have to set up your machine before you start working with &#8220;yo generator&#8221;. The complete setup can be found <a href="https://github.com/pnp/generator-teams/wiki/Setup-Machine" target="_blank" rel="noreferrer noopener nofollow">here</a>, I am just mentioning it here, even though it is not relevant to this article. So here I will create a Teams App using Javascript SDK and I will connect the same with my Vuejs application later, I will write about that in my next blog.</p>



<h2 class="wp-block-heading">What we are going to do</h2>



<p>We will be doing preceding things in this post,</p>



<ol class="wp-block-list"><li>Create an Azure function with Node Js HttpTrigger</li><li>Customize the Azure function to use static HTML file we upload</li><li>Generate the Index.html file, config.html file as per Microsoft Teams Web App standard</li><li>Generate the manifest file</li><li>Install our new Web App in Microsoft Team</li></ol>



<p>Are you still with me and above mentioned points sounds interesting for you, then let&#8217;s develop something.</p>



<h3 class="wp-block-heading">Create Static Website Using JavaScript SDK</h3>



<p>Here we are going to use <a href="https://docs.microsoft.com/en-us/javascript/api/overview/msteams-client/?WT.mc_id=AZ-MVP-5001828" target="_blank" rel="noreferrer noopener">Microsoft Teams JavaScript client SDK</a> to develop our application. And with the help of these SDK, we can develop a wide variety of applications, some of them are listed below.</p>



<ul class="wp-block-list"><li>Tabs</li><li>Bots</li><li>Messaging Extensions</li><li>Task Modules</li><li>Webhooks and Office 365 connector</li></ul>



<p>And within the Tab type, we can develop a static Tab application (The tabs that are shown in the left side of the Teams application, here the context will be same for all the users) and a configurable tab application (The tab we can add to any channel, or groups and can be configurable with logged-in users context). </p>



<p>Here we are going to develop a small application that just shows the logged in user email id on our home page. Just remember that this is just a starting blog and the motive of this blog is to give you a walkthrough on how you can develop and install custom apps in Microsoft Teams. To develop the application for Microsoft Teams, we need the below pages.</p>



<ol class="wp-block-list"><li>Content Page(index.html), this is the page that displayed in the Tab app</li><li>Configuration Page(config.html), that used to set the content page</li></ol>



<p>Now open any of your favorite code editors and create two files index.html and config.html and then replace the codes. </p>



<script src="https://gist.github.com/SibeeshVenu/e68fc11f0e32e54fabb4c2b6a5c51dda.js"></script>



<p>Here we are just setting our Tab&#8217;s name and then we are calling &#8220;microsoftTeams.settings.setValidityState(true)&#8221;, at then end the Save button will be enabled for you after the validation. Please remember that you should call &#8220;microsoftTeams.initialize()&#8221; before you perform any of these tasks. </p>



<script src="https://gist.github.com/SibeeshVenu/5383a31253265957a8c25a489add0d8a.js"></script>



<p>Here on our content page, we are just getting the logged-in user name and show it to a div element. As simple as that. </p>



<h3 class="wp-block-heading">Static Website Using Azure Fucntion</h3>



<p>The capabilities of an Azure Function is limitless, it is up to you for what the Azure Function can be used. Now we are going to use the Azure function to host a static website. &nbsp;I hope you have already used Azure Functions, if you have not, you can read some related articles&nbsp;<a href="https://sibeeshpassion.com/tag/azure-function/">here</a>.</p>



<p>Now go to your Azure portal and search for Function App and create one. Remember to select the <strong>Nodejs as runtime stack</strong>. Once the function app is deployed successfully go to the Functions tab and click on the plus icon.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="691" height="327" src="https://sibeeshpassion.com/wp-content/uploads/2020/06/create-azure-function.png" alt="" class="wp-image-14123" srcset="/wp-content/uploads/2020/06/create-azure-function.png 691w, /wp-content/uploads/2020/06/create-azure-function-300x142.png 300w, /wp-content/uploads/2020/06/create-azure-function-425x201.png 425w" sizes="(max-width: 691px) 100vw, 691px" /><figcaption>create azure function</figcaption></figure>



<p>From the template section, select the template HttpTrigger and then give a name for your function and set the authorization level to anonymous for now. You should see your function now and we can edit the code now. Go to your function and click on the button Code + Test.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="867" height="687" src="https://sibeeshpassion.com/wp-content/uploads/2020/06/azure-function-code-test.png" alt="" class="wp-image-14124" srcset="/wp-content/uploads/2020/06/azure-function-code-test.png 867w, /wp-content/uploads/2020/06/azure-function-code-test-300x238.png 300w, /wp-content/uploads/2020/06/azure-function-code-test-768x609.png 768w, /wp-content/uploads/2020/06/azure-function-code-test-425x337.png 425w" sizes="(max-width: 867px) 100vw, 867px" /><figcaption>Code+Test</figcaption></figure>



<p>Here is the place where you can edit your function code. Replace the codes with the below one. </p>



<script src="https://gist.github.com/SibeeshVenu/ff4cba0a4a88d6a743e742c0581ab8f0.js"></script>



<p>Here we are loading our index.html file from the directory &#8220;myfiles&#8221; and add it as the context body so that the page will be displayed. Save the function and now we can create the folder &#8220;myfiles&#8221; and upload our pages there. To do that, go to your Azure Function and then click on Advanced Tools and click on the Goto link if it is asked. This will open a new browser tab with advanced tools. You can also visit this page by directly go to <strong>https://{yourfunctionname}.scm.azurewebsites.net/</strong>. Now click on the Debug console on the menu and then select CMD, go to the folder site -&gt; wwwroot -&gt; folder with the name of your function, this is where you will see the files function.json and index.js. Just click on the + (plus) icon on the top and create a new folder with the name &#8220;myfiles&#8221;. Go to the folder created and drag and drop your files there (index.html, config.html).</p>



<p>At this point, you should be able to see your index page, when you go to your function URL (https://yourfunctionname.azurewebsites.net/api/triggername?file=index.html), but if you go to the home page of your function by visiting https://yourfunctionname.azurewebsites.net, your index file is not loading right? We can override this by introducing a new proxy to our application. </p>



<p>Go to your Function App and click on the Proxies menu and then click on the +Add icon on the top. Fill the form given, your filled form should look like below.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="675" height="946" src="https://sibeeshpassion.com/wp-content/uploads/2020/06/azure-function-proxy.png" alt="" class="wp-image-14126" srcset="/wp-content/uploads/2020/06/azure-function-proxy.png 675w, /wp-content/uploads/2020/06/azure-function-proxy-214x300.png 214w, /wp-content/uploads/2020/06/azure-function-proxy-392x550.png 392w" sizes="(max-width: 675px) 100vw, 675px" /><figcaption>Azure Function Proxy</figcaption></figure>



<p>Once the proxy is updated, go to your function home page and your index page should be loaded with the Team JavaScript SDK now, you can check this in the network tab in the browser console. </p>



<h3 class="wp-block-heading">Create Manifest for Teams App</h3>



<p>Now that our static website is ready, it is time to create a manifest for our team&#8217;s application. You can either create this manifest on your own, or you can use the tool called App Studio, <a href="https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/build-and-test/app-studio-overview?WT.mc_id=AZ-MVP-5001828" target="_blank" rel="noreferrer noopener">here is the well-documented page which explains the features</a> on this application. By using this tool we generate a manifest file by giving the static page files and other information. And at the end of the process, if all the validations are successful, then you will be given options to download the manifest file and install the app to any channel, or teams.</p>



<p>Here is the sample manifest file generated.</p>



<script src="https://gist.github.com/SibeeshVenu/6d1802af3244df9d3b2ecd88888a9470.js"></script>



<p>If you want to understand the complete structure of the manifest file, <a href="https://docs.microsoft.com/en-us/microsoftteams/platform/resources/schema/manifest-schema/?WT.mc_id=AZ-MVP-5001828" target="_blank" rel="noreferrer noopener">here is the link</a>.</p>



<h3 class="wp-block-heading">Install the Teams App in Teams</h3>



<p>If you choose the option of downloading the manifest file, here is how you can install it. Click on the three-dot on the static tabs in Teams and then click on the More Apps link.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="742" height="922" src="https://sibeeshpassion.com/wp-content/uploads/2020/06/more-apps-option.png" alt="" class="wp-image-14127" srcset="/wp-content/uploads/2020/06/more-apps-option.png 742w, /wp-content/uploads/2020/06/more-apps-option-241x300.png 241w, /wp-content/uploads/2020/06/more-apps-option-425x528.png 425w" sizes="(max-width: 742px) 100vw, 742px" /><figcaption>Add more apps</figcaption></figure>



<p>Now click on the &#8220;Upload a custom app&#8221; link at the bottom and then select your manifest zip file downloaded, it will contain the manifest.json file and other related files. Clicking on the &#8220;Add to a team&#8221; button on the next screen will start the process.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="797" src="https://sibeeshpassion.com/wp-content/uploads/2020/06/add-app-to-a-team-1024x797.png" alt="" class="wp-image-14128" srcset="/wp-content/uploads/2020/06/add-app-to-a-team-1024x797.png 1024w, /wp-content/uploads/2020/06/add-app-to-a-team-300x234.png 300w, /wp-content/uploads/2020/06/add-app-to-a-team-768x598.png 768w, /wp-content/uploads/2020/06/add-app-to-a-team-1536x1196.png 1536w, /wp-content/uploads/2020/06/add-app-to-a-team-425x331.png 425w, /wp-content/uploads/2020/06/add-app-to-a-team.png 1782w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Add app to Team</figcaption></figure>



<p>In the next screen, select the channel you want to add this Tab App, and then click on the &#8220;Setup a tab&#8221; button. Once it is installed, you should see your email if you go to your Tab Application.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="191" src="https://sibeeshpassion.com/wp-content/uploads/2020/06/output-1024x191.png" alt="" class="wp-image-14129" srcset="/wp-content/uploads/2020/06/output-1024x191.png 1024w, /wp-content/uploads/2020/06/output-300x56.png 300w, /wp-content/uploads/2020/06/output-768x143.png 768w, /wp-content/uploads/2020/06/output-425x79.png 425w, /wp-content/uploads/2020/06/output.png 1238w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Output</figcaption></figure>



<h2 class="wp-block-heading">Conclusion</h2>



<p>I hope this post was useful and you have learned the below things.</p>



<ol class="wp-block-list"><li>What are Microsoft Teams Web App?</li><li>How to create a custom application for Microsoft Teams?</li><li>How to load a static website using the Azure Function?</li><li>What is Manifest and how to generate it using App Studio?</li><li>How to install the Web Apps in Microsoft Teams?</li></ol>



<h2 class="wp-block-heading">About the Author</h2>



<p>I am yet another developer who is passionate about writing and video creation. I have written close to 500 blogs on my&nbsp;<a href="https://sibeeshpassion.com/" target="_blank" rel="noreferrer noopener">blog</a>. And I upload videos on my YouTube channels&nbsp;<a href="https://www.youtube.com/njanorumalayali" target="_blank" rel="noreferrer noopener">Njan Oru Malayali</a>&nbsp;and&nbsp;<a href="https://www.youtube.com/SibeeshPassion" target="_blank" rel="noreferrer noopener">Sibeesh Passion</a>. Please feel free to follow me.</p>



<ul class="wp-block-list"><li><a href="https://github.com/SibeeshVenu">GitHub</a></li><li><a href="https://medium.com/@sibeeshvenu">medium</a></li><li><a href="https://twitter.com/sibeeshvenu">Twitter</a></li></ul>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post useful? Kindly do not forget to share your feedback.<a href="https://sibeeshpassion.com/create-microsoft-teams-app-using-vuejs-azure-javascript-sdk/" target="_blank" rel="noreferrer noopener"> <strong>In the next post, we will see how we can connect this application to our Vuejs application</strong></a>.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/create-custom-web-apps-for-microsoft-teams-using-azure-function-node-js/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Azure Function Job to Delete Azure Blobs from Blob Containers</title>
		<link>https://sibeeshpassion.com/azure-function-job-to-delete-azure-blobs-from-blob-containers/</link>
					<comments>https://sibeeshpassion.com/azure-function-job-to-delete-azure-blobs-from-blob-containers/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Wed, 24 Jul 2019 15:24:49 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Azure Automation with Azure Function]]></category>
		<category><![CDATA[Azure Blob]]></category>
		<category><![CDATA[Azure Container]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[Azure Job]]></category>
		<category><![CDATA[Azure Storage]]></category>
		<category><![CDATA[Delete blobs using Azure Function]]></category>
		<category><![CDATA[Serverless]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13852</guid>

					<description><![CDATA[[toc] Introduction I have tried many things with Azure Functions and you should be able to see then here. Here in this post we are going to see how we can create a job which runs in a particular day and time to delete the blobs we have in a blob containers in our Azure Storage Account. If you want to know how you can upload to the blobs using Azure Function, consider reading my article here. Prerequisites You should have a valid Azure Subscription You should have a running Azure Function If you are not sure about how to [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>I have tried many things with Azure Functions and you should be able to see then <a href="https://sibeeshpassion.com/tag/azure-function/">here</a>. Here in this post we are going to see how we can create a job which runs in a particular day and time to delete the blobs we have in a blob containers in our Azure Storage Account. If you want to know how you can upload to the blobs using Azure Function, consider reading my article <a href="https://sibeeshpassion.com/timertrigger-azure-function-to-upload-to-azure-blob-daily/">here</a>. </p>



<h2 class="wp-block-heading">Prerequisites</h2>



<ul class="wp-block-list"><li>You should have a valid Azure Subscription </li><li>You should have a running Azure Function</li><li>If you are not sure about how to create an Azure Function App, <a href="https://sibeeshpassion.com/iothubtrigger-azure-function-and-azure-iot-hub/#creating-an-azure-function-app"><em>this post</em></a> may help you.</li><li>You should have a valid Azure Storage Account</li></ul>



<h2 class="wp-block-heading">Using the code</h2>



<h3 class="wp-block-heading">Configure the Dependency Injection in Azure Function</h3>



<p>As we are going to inject our dependency via constructor we need to configure the same by creating a Startup.cs class in our solution. Let&#8217;s do that first. To configure, make sure that you had installed the Nuget Package <strong><em>Microsoft.Azure.Functions.Extensions</em></strong>. </p>



<p>Now create a new class and name it as Startup.cs and write the code as preceding. </p>



<script src="https://gist.github.com/SibeeshVenu/e60c3c180bd2052938e848ddbe951652.js"></script>



<p>Here we are adding a singleton service for our IBlobService. Do not forget to inherit your <em>Startup </em>class from  <em>FunctionsStartup</em>.</p>



<h3 class="wp-block-heading">Write the Azure Function </h3>



<p>As we have set up our Startup class, now let us create our Azure Function. Follow <a href="https://sibeeshpassion.com/timertrigger-azure-function-to-upload-to-azure-blob-daily/#creating-an-azure-function-in-function-app"><strong>this post</strong></a> to see how you can create one. And you can write the code as preceding.</p>



<script src="https://gist.github.com/SibeeshVenu/9455c80616c051f13a989553eb8b9425.js"></script>



<p>Here we are making the Function to run on every Monday at 4 AM using the CRON expression. Make sure to check my previous post to see more about the CRON expression.</p>



<p>Below are the blob container names I have in my Azure Blob Storage.</p>



<script src="https://gist.github.com/SibeeshVenu/00ba5ed0b4ce1cf4464dcf8c06d996c1.js"></script>



<p>Make sure to use the small letters for your Azure Blob Container names, otherwise you will see an exception as mentioned <a href="https://stackoverflow.com/questions/45305556/azure-table-storage-names-invalid-characters/57180310#57180310">here</a>. </p>



<h3 class="wp-block-heading">Creating the Blob Service</h3>



<p>Now let us create a new Interface for our service.</p>



<script src="https://gist.github.com/SibeeshVenu/3e86c52da6ea5689610b16607f263f2c.js"></script>



<p>And then create a service <strong>BlobService</strong>.</p>



<script src="https://gist.github.com/SibeeshVenu/3e0baeaa3e02dd95721a716ef517119c.js"></script>



<p>Here you can see that in the <em>PerformTasks </em>function we are getting the blob container reference and then get all the blobs using <em>ListBlobsSegmentedAsync</em> and then cast it as <em>ICloudBlob</em> so that we can easily delete the blobs. </p>



<p>Make sure to add the <em>AzureWebJobsStorage</em> in your local.settings.json file and in the Azure Function Configuration in the portal.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Wow!. Now we have learned,</p>



<ul class="wp-block-list"><li>about Azure Function and setting up the same</li><li>about Time Trigger in Azure Function</li><li>about CRON expressions in Azure Function</li><li>how to set up dependency injection in Azure Function</li><li>how to delete Azure blobs from Azure Blob Containers using Azure Function</li></ul>



<p>You can always ready my Azure articles&nbsp;<a href="https://sibeeshpassion.com/category/azure/">here</a>.</p>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/azure-function-job-to-delete-azure-blobs-from-blob-containers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>TimerTrigger Azure Function to Upload to Azure Blob Daily</title>
		<link>https://sibeeshpassion.com/timertrigger-azure-function-to-upload-to-azure-blob-daily/</link>
					<comments>https://sibeeshpassion.com/timertrigger-azure-function-to-upload-to-azure-blob-daily/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Wed, 17 Jul 2019 17:36:35 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Azure Blob]]></category>
		<category><![CDATA[Azure Blobs]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[Azure Function and Azure Storage Blob]]></category>
		<category><![CDATA[Azure Storage]]></category>
		<category><![CDATA[CRON Expressions]]></category>
		<category><![CDATA[Time Trigger Azure Function]]></category>
		<category><![CDATA[Upload to Azure Blob]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13840</guid>

					<description><![CDATA[[toc] Introduction Working with Azure Function is always fun and with the help of other Azure Services, it gets even better. Here in this article, we are going to see how we can use the TimerTrigger of Azure Function to upload some file to the Azure Blob storage daily. The basic idea is to have job running every data at a specific time to perform the upload. I believe, this is enough for the introduction, let us start implementing them. Background If you are new to Azure Functions, I recommend you to read some related articles from here. The possibilities [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>Working with Azure Function is always fun and with the help of other Azure Services, it gets even better. Here in this article, we are going to see how we can use the TimerTrigger of Azure Function to upload some file to the Azure Blob storage daily. The basic idea is to have job running every data at a specific time to perform the upload. I believe, this is enough for the introduction, let us start implementing them.</p>



<h2 class="wp-block-heading">Background</h2>



<p>If you are new to Azure Functions, I recommend you to read some related articles from <a href="https://sibeeshpassion.com/tag/azure-function/"><em>here</em></a>. The possibilities that you can do with Azure Function is countless, and here we are going to discuss one of them. We live in a world everything is automated, nobody is interested in doing any manual works. Writing an automated Job which runs everyday at a given time is never been easier with the help of Azure Function. </p>



<h2 class="wp-block-heading">Prerequisites</h2>



<ul class="wp-block-list"><li>You should have a valid Azure Subscription </li><li>You should have a running Azure Function</li><li>If you are not sure about how to create an Azure Function App, <a href="https://sibeeshpassion.com/iothubtrigger-azure-function-and-azure-iot-hub/#creating-an-azure-function-app"><em>this post</em></a> may help you.</li><li>You should have a valid Azure Storage Account</li></ul>



<h2 class="wp-block-heading">Azure Function and Azure Blob</h2>



<h3 class="wp-block-heading">Get the Storage Connection String</h3>



<p>By default a new key with the name AzureWebJobsStorage will be created when you create an Azure Function in your Visual Studio Azure Function App. If it doesn&#8217;t you should create this in your local.settings.json file by getting the connection string from your storage account. </p>



<p>To get the connection string, go to your storage account and click on Access Keys under Settings blade. And then copy any one of the connection string listed. You can use this value to create the AzureWebJobsStorage key under Values in the local.settings.json file. You should also create this in the Azure Function configuration in the Azure Portal, as this local.settings.json file is just for local and it will not be pushed to the Azure Function when you publish your Functions.</p>



<h3 class="wp-block-heading">Creating an Azure Function in Function App</h3>



<p>To create a new Azure Function in the Azure Function App, right click on your project and then click on <strong>Add</strong> and then select <strong>New Azure Function</strong>. In the coming pop up you should be given an option to name your Azure Function. Once that is done you can choose what trigger you want to use, in this case I will select <strong>TimeTrigger</strong>. </p>



<figure class="wp-block-image"><img decoding="async" width="649" height="422" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Creating-Time-Trigger-Azure-Function.png" alt="" class="wp-image-13841" srcset="/wp-content/uploads/2019/07/Creating-Time-Trigger-Azure-Function.png 649w, /wp-content/uploads/2019/07/Creating-Time-Trigger-Azure-Function-300x195.png 300w, /wp-content/uploads/2019/07/Creating-Time-Trigger-Azure-Function-425x276.png 425w" sizes="(max-width: 649px) 100vw, 649px" /><figcaption>Azure Function with Time Trigger</figcaption></figure>



<p>Once you click on Ok, a new Function will be created for you with the time interval of 5 minutes. The Time Trigger Function uses NCronTab library to intercept the CRON expression. This is the expression that you see under the Schedule option on the above image. A usual CRON express has the below fields in it.</p>



<script src="https://gist.github.com/SibeeshVenu/7ed2aec377fe6750e9ba6239039399f2.js"></script>



<p>If you see the code you can see that a function Run is been created for you, with the time interval you had set.</p>



<script src="https://gist.github.com/SibeeshVenu/197d93ab68a634528ec81cc96bba5911.js"></script>



<p>Now we can say our Azure Function to run everyday at 9.45 AM by changing the CRON expression.</p>



<script src="https://gist.github.com/SibeeshVenu/f2fab09a36ac46c430759ee332fed5ae.js"></script>



<p>You can learn more about the CRON expressions <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer#cron-expressions">here</a>.</p>



<h3 class="wp-block-heading">Upload the Data to Azure Blob</h3>



<p>Now that we have our Azure Function ready to be run everyday as we wanted. It is time to write some code to generate the data and upload it to the blob. Before we do that we should make sure that we have installed the required Nuget package Microsoft.Azure.Storage.Blob.</p>



<figure class="wp-block-image"><img decoding="async" width="493" height="161" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Install-Microsoft.Azure_.Storage.Blob_.png" alt="" class="wp-image-13843" srcset="/wp-content/uploads/2019/07/Install-Microsoft.Azure_.Storage.Blob_.png 493w, /wp-content/uploads/2019/07/Install-Microsoft.Azure_.Storage.Blob_-300x98.png 300w, /wp-content/uploads/2019/07/Install-Microsoft.Azure_.Storage.Blob_-425x139.png 425w" sizes="(max-width: 493px) 100vw, 493px" /><figcaption> Install Microsoft.Azure.Storage.Blob </figcaption></figure>



<p>Now we can rewrite the complete Function code as below.</p>



<script src="https://gist.github.com/SibeeshVenu/d197438dbe31e7f54e3a2907ecf9afe0.js"></script>



<p>As you can see that, I am creating an instance of CloudStorageAccount and then create a blob client by calling the function CreateCloudBlobClient(). Once we get that, we get the blob container reference by using the function GetContainerReference() and then get the block blob and finally call the UploadFromStreamAsync() function to upload the stream data. </p>



<p>The line var stream = getTheImportedData.ConvertToStream(); is to get the stream data from an API, which returns a JSON and then I convert it to a stream by calling an extension method. </p>



<script src="https://gist.github.com/SibeeshVenu/68f9c7d76b2510b547d90508f276fa5f.js"></script>



<p>Here EnviornmentVariables.StorageConnectionString is part of a shared static class which returns the AzureWebJobsStorage we set in the local.settings.json file.</p>



<script src="https://gist.github.com/SibeeshVenu/f24829a6b62cf31399ea95ec15d70d2e.js"></script>



<h2 class="wp-block-heading">Output</h2>



<p>Now let us run our function in local and test. You should see an output as preceding.</p>



<figure class="wp-block-image"><img decoding="async" width="649" height="100" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Http-Trigger-Azure-Function-Output.png" alt="" class="wp-image-13844" srcset="/wp-content/uploads/2019/07/Http-Trigger-Azure-Function-Output.png 649w, /wp-content/uploads/2019/07/Http-Trigger-Azure-Function-Output-300x46.png 300w, /wp-content/uploads/2019/07/Http-Trigger-Azure-Function-Output-425x65.png 425w" sizes="(max-width: 649px) 100vw, 649px" /><figcaption>Time Trigger Azure Function Output</figcaption></figure>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Wow!. Now we have learned,</p>



<ul class="wp-block-list"><li>about Azure Function and setting up the same</li><li>about Time Trigger in Azure Function</li><li>about CRON expressions in Azure Function</li><li>how to upload data to Azure blob using Azure Function</li></ul>



<p>You can always ready my Azure articles&nbsp;<a href="https://sibeeshpassion.com/category/azure/">here</a>.</p>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/timertrigger-azure-function-to-upload-to-azure-blob-daily/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Azure Function Build and Release Pipeline in Azure DevOps CI CD</title>
		<link>https://sibeeshpassion.com/azure-function-build-and-release-pipeline-in-azure-devops-ci-cd/</link>
					<comments>https://sibeeshpassion.com/azure-function-build-and-release-pipeline-in-azure-devops-ci-cd/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 09 Jul 2019 11:10:48 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Azure DevOps]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[Build Pipeline]]></category>
		<category><![CDATA[CI and CD]]></category>
		<category><![CDATA[Continuous Deployment]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[DevOps]]></category>
		<category><![CDATA[Release Pipeline]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13794</guid>

					<description><![CDATA[[toc] Introduction Playing with Azure Function is always a nice feeling, and it is very important to configure both build and release pipeline for all of your applications, Azure Functions are not different. In this article, we will see how we can create both build and release pipeline in Azure DevOps for our Azure Function application. I hope you will like it. Prerequisites You should have an Azure Function application to configure the build and release pipeline for the same. You can either create a new one in the Azure portal, or you can use any existing azure functions available [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>Playing with <a href="https://sibeeshpassion.com/tag/azure-function/">Azure Function</a> is always a nice feeling, and it is very important to configure both build and release pipeline for all of your applications, Azure Functions are not different. In this article, we will see how we can create both build and release pipeline in <a href="https://sibeeshpassion.com/tag/azure-devops/">Azure DevOps</a> for our Azure Function application. I hope you will like it.</p>



<h2 class="wp-block-heading">Prerequisites </h2>



<p>You should have an Azure Function application to configure the build and release pipeline for the same. You can either create a <a href="https://sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/#creating-an-azure-function-solution-and-function">new one in the Azure portal</a>, or you can use any existing azure functions available in internet, for example you can see one <a href="https://github.com/SibeeshVenu/Realtime-IoT-Device-Data-using-Azure-SignalR-and-Azure-Function-in-Angular">here</a>.</p>



<h2 class="wp-block-heading">Setting Build Pipeline for Azure Function</h2>



<p>Go to your Azure DevOps and click on Builds</p>



<figure class="wp-block-image"><img decoding="async" width="505" height="581" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Select-Build.png" alt="" class="wp-image-13795" srcset="/wp-content/uploads/2019/07/Select-Build.png 505w, /wp-content/uploads/2019/07/Select-Build-261x300.png 261w, /wp-content/uploads/2019/07/Select-Build-425x489.png 425w" sizes="(max-width: 505px) 100vw, 505px" /><figcaption>Select Builds</figcaption></figure>



<p>Now you should see an option to select where your code is available. You can choose accordingly.</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="542" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Select-Code-Source.png" alt="" class="wp-image-13796" srcset="/wp-content/uploads/2019/07/Select-Code-Source.png 650w, /wp-content/uploads/2019/07/Select-Code-Source-300x250.png 300w, /wp-content/uploads/2019/07/Select-Code-Source-425x354.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Select Code Source</figcaption></figure>



<p>As my project is in Azure repository, I will select that. Please be noted that I will be using the classic editor to create the pipeline now, so that I can show the steps with the screenshots. You should be able to see the final yml file at the end of the configuration.</p>



<p>Now you can select the template of your project, I will select .Net Core as the template as my Azure Function is in .Net Core.</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="319" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Select-Template.png" alt="" class="wp-image-13797" srcset="/wp-content/uploads/2019/07/Select-Template.png 650w, /wp-content/uploads/2019/07/Select-Template-300x147.png 300w, /wp-content/uploads/2019/07/Select-Template-425x209.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Asp.Net Core as Template</figcaption></figure>



<p>Now you can see that our Pipeline is created with some default tasks and settings as follows.</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="586" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Pipeline-Tasks.png" alt="" class="wp-image-13824" srcset="/wp-content/uploads/2019/07/Pipeline-Tasks.png 650w, /wp-content/uploads/2019/07/Pipeline-Tasks-300x270.png 300w, /wp-content/uploads/2019/07/Pipeline-Tasks-425x383.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Pipeline Taks</figcaption></figure>



<figure class="wp-block-image"><img decoding="async" width="650" height="428" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Pipeline-Settings.png" alt="" class="wp-image-13799" srcset="/wp-content/uploads/2019/07/Pipeline-Settings.png 650w, /wp-content/uploads/2019/07/Pipeline-Settings-300x198.png 300w, /wp-content/uploads/2019/07/Pipeline-Settings-425x280.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Pipeline Settings for Azure Function</figcaption></figure>



<p>As everything is already created for us, let us save and queue the build. Please make sure that your source code branch is valid and you had verified the build. I forgot to do this, and I was getting the below error, as there was some issue with my code (there was an additional dot(.) in my code, I added it by mistake).</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="696" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Initial-Build-Run-Error.png" alt="" class="wp-image-13800" srcset="/wp-content/uploads/2019/07/Initial-Build-Run-Error.png 650w, /wp-content/uploads/2019/07/Initial-Build-Run-Error-280x300.png 280w, /wp-content/uploads/2019/07/Initial-Build-Run-Error-425x455.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Initial Build Error</figcaption></figure>



<p>So I edited my code and build, and then initiate a manual build again. But even after that I was getting an error as &#8220;No web project was found in the repository. Web projects are identified by presence of either a web.config file or wwwroot folder in the directory&#8221;.</p>



<figure class="wp-block-image"><img decoding="async" width="651" height="114" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Second-Build-Error.png" alt="" class="wp-image-13801" srcset="/wp-content/uploads/2019/07/Second-Build-Error.png 651w, /wp-content/uploads/2019/07/Second-Build-Error-300x53.png 300w, /wp-content/uploads/2019/07/Second-Build-Error-425x74.png 425w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Second Build Error</figcaption></figure>



<p>The reason for this is, that by default the &#8220;Publish Web Projects&#8221; is enabled in the Publish task. As ours is not a web project, and if this option is enabled the Publish task will look for a web project in the repository and run the publish command. If we have a web.config file or a wwwroot folder in the directory, it is been treated as a web project. </p>



<p>We have to disable this option as it is not applicable for our project, as it is not a web project. To do so, please go to your Publish task.</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="576" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/All-Tasks.png" alt="" class="wp-image-13826" srcset="/wp-content/uploads/2019/07/All-Tasks.png 650w, /wp-content/uploads/2019/07/All-Tasks-300x266.png 300w, /wp-content/uploads/2019/07/All-Tasks-425x377.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>All Tasks</figcaption></figure>



<p>Now you should deselect the &#8220;Publish Web Projects&#8221; option.</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="613" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Unselect-Publish-Web-Project-Option.png" alt="" class="wp-image-13803" srcset="/wp-content/uploads/2019/07/Unselect-Publish-Web-Project-Option.png 650w, /wp-content/uploads/2019/07/Unselect-Publish-Web-Project-Option-300x283.png 300w, /wp-content/uploads/2019/07/Unselect-Publish-Web-Project-Option-425x401.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Deselect  Publish Web Projects </figcaption></figure>



<p>Now save your build configuration and queue a new build. If everything goes well, you should see that your build is successful.</p>



<figure class="wp-block-image"><img decoding="async" width="651" height="288" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Build-Success.png" alt="" class="wp-image-13804" srcset="/wp-content/uploads/2019/07/Build-Success.png 651w, /wp-content/uploads/2019/07/Build-Success-300x133.png 300w, /wp-content/uploads/2019/07/Build-Success-425x188.png 425w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Build Success</figcaption></figure>



<p>If you wish to see the YAML code of a task, you should be able to see it if you click on &#8220;View YAML&#8221; link.</p>



<figure class="wp-block-image"><img decoding="async" width="1000" height="208" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/View-YAML-of-one-Task.png" alt="" class="wp-image-13834" srcset="/wp-content/uploads/2019/07/View-YAML-of-one-Task.png 1000w, /wp-content/uploads/2019/07/View-YAML-of-one-Task-300x62.png 300w, /wp-content/uploads/2019/07/View-YAML-of-one-Task-768x160.png 768w, /wp-content/uploads/2019/07/View-YAML-of-one-Task-425x88.png 425w" sizes="(max-width: 1000px) 100vw, 1000px" /></figure>



<p>Please do not forget to enable if you need to trigger the build automatically when there is a check in happened in the repository.</p>



<figure class="wp-block-image"><img decoding="async" width="1004" height="97" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Enable-Disable-Continous-Integration.png" alt="" class="wp-image-13808" srcset="/wp-content/uploads/2019/07/Enable-Disable-Continous-Integration.png 1004w, /wp-content/uploads/2019/07/Enable-Disable-Continous-Integration-300x29.png 300w, /wp-content/uploads/2019/07/Enable-Disable-Continous-Integration-768x74.png 768w, /wp-content/uploads/2019/07/Enable-Disable-Continous-Integration-425x41.png 425w" sizes="(max-width: 1004px) 100vw, 1004px" /><figcaption>Enable or Disable Continuous Integration </figcaption></figure>



<h2 class="wp-block-heading">Setting Release Pipeline for Azure Function</h2>



<p>Now that we have got our build successful, let us go ahead and create a release pipeline for our Azure Function. But before we do that, we need to create a service connection in our Azure DevOps project. To create one, please go to your Azure DevOps projects settings -&gt; Pipelines -&gt; Service Connections. </p>



<figure class="wp-block-image"><img decoding="async" width="1000" height="690" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Azure-Resource-Manager-Connection.png" alt="" class="wp-image-13809" srcset="/wp-content/uploads/2019/07/Azure-Resource-Manager-Connection.png 1000w, /wp-content/uploads/2019/07/Azure-Resource-Manager-Connection-300x207.png 300w, /wp-content/uploads/2019/07/Azure-Resource-Manager-Connection-768x530.png 768w, /wp-content/uploads/2019/07/Azure-Resource-Manager-Connection-425x293.png 425w" sizes="(max-width: 1000px) 100vw, 1000px" /><figcaption>Azure Resource Manager Connection</figcaption></figure>



<p>Once it is created, you should see the same under your service connections slab. Now go to the Pipelines section of your Azure DevOps project and click on Releases and the click on New pipeline and select Azure App Service Deployment as the template.</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="370" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Azure-App-Service-Deployment-Task-1024x370.png" alt="" class="wp-image-13810" srcset="/wp-content/uploads/2019/07/Azure-App-Service-Deployment-Task-1024x370.png 1024w, /wp-content/uploads/2019/07/Azure-App-Service-Deployment-Task-300x108.png 300w, /wp-content/uploads/2019/07/Azure-App-Service-Deployment-Task-768x278.png 768w, /wp-content/uploads/2019/07/Azure-App-Service-Deployment-Task-425x154.png 425w, /wp-content/uploads/2019/07/Azure-App-Service-Deployment-Task.png 1176w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Azure App Service Deployment</figcaption></figure>



<p>You should see this task in the Task section of your pipeline. If you are unable to see the service connection that you had created on the right panel, just remove the task and add the same again and then check. Your task definition should be looking as below.</p>



<figure class="wp-block-image"><img decoding="async" width="677" height="1024" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Azure-App-Service-Deploy-Task-677x1024.png" alt="" class="wp-image-13811" srcset="/wp-content/uploads/2019/07/Azure-App-Service-Deploy-Task-677x1024.png 677w, /wp-content/uploads/2019/07/Azure-App-Service-Deploy-Task-198x300.png 198w, /wp-content/uploads/2019/07/Azure-App-Service-Deploy-Task-364x550.png 364w, /wp-content/uploads/2019/07/Azure-App-Service-Deploy-Task.png 746w" sizes="(max-width: 677px) 100vw, 677px" /><figcaption>Azure App Service Deploy Task</figcaption></figure>



<p>Once you are done, save your pipeline. And before you create a release, make sure that you had assigned the right build artifacts. Click on Add an artifact.</p>



<figure class="wp-block-image"><img decoding="async" width="1008" height="736" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Release-Pipeline.png" alt="" class="wp-image-13812" srcset="/wp-content/uploads/2019/07/Release-Pipeline.png 1008w, /wp-content/uploads/2019/07/Release-Pipeline-300x219.png 300w, /wp-content/uploads/2019/07/Release-Pipeline-768x561.png 768w, /wp-content/uploads/2019/07/Release-Pipeline-315x230.png 315w, /wp-content/uploads/2019/07/Release-Pipeline-425x310.png 425w" sizes="(max-width: 1008px) 100vw, 1008px" /><figcaption>Add an Artifact Option</figcaption></figure>



<p>Now you should set the artifacts properties.</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="728" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Assign-Artifact-Properties.png" alt="" class="wp-image-13814" srcset="/wp-content/uploads/2019/07/Assign-Artifact-Properties.png 650w, /wp-content/uploads/2019/07/Assign-Artifact-Properties-268x300.png 268w, /wp-content/uploads/2019/07/Assign-Artifact-Properties-425x476.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Assign Artifacts Properties </figcaption></figure>



<p>Click on Add and Save your pipeline and then queue a release by clicking on the button Create release. You may get the error &#8221; Error: More than one package matched with specified pattern: d:\a\r1\a\**\*.zip. Please restrain the search pattern&#8221; now.</p>



<figure class="wp-block-image"><img decoding="async" width="1000" height="221" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/More-than-One-Package-Matched.png" alt="" class="wp-image-13836" srcset="/wp-content/uploads/2019/07/More-than-One-Package-Matched.png 1000w, /wp-content/uploads/2019/07/More-than-One-Package-Matched-300x66.png 300w, /wp-content/uploads/2019/07/More-than-One-Package-Matched-768x170.png 768w, /wp-content/uploads/2019/07/More-than-One-Package-Matched-425x94.png 425w" sizes="(max-width: 1000px) 100vw, 1000px" /><figcaption>Error</figcaption></figure>



<p> The reason behind this is, that your solution has many projects in it and each projects will be having its own zip folder in the artifacts, so to fix this we should specify our Azure Function Project in the Package section of our pipeline task.</p>



<p>Click on the Azure App service Deploy task and the go to the Package or Folder section and then click on the three dots.</p>



<figure class="wp-block-image"><img decoding="async" width="1000" height="145" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Package-or-Folder-Option.png" alt="" class="wp-image-13816" srcset="/wp-content/uploads/2019/07/Package-or-Folder-Option.png 1000w, /wp-content/uploads/2019/07/Package-or-Folder-Option-300x44.png 300w, /wp-content/uploads/2019/07/Package-or-Folder-Option-768x111.png 768w, /wp-content/uploads/2019/07/Package-or-Folder-Option-425x62.png 425w" sizes="(max-width: 1000px) 100vw, 1000px" /><figcaption>Package or Folder Option</figcaption></figure>



<p>Now you should have an option to select the right zip file.</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="676" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Choose-the-Correct-zip.png" alt="" class="wp-image-13817" srcset="/wp-content/uploads/2019/07/Choose-the-Correct-zip.png 650w, /wp-content/uploads/2019/07/Choose-the-Correct-zip-288x300.png 288w, /wp-content/uploads/2019/07/Choose-the-Correct-zip-425x442.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Choose the Right Zip File</figcaption></figure>



<p>Now Create the release again and you should see that the release is successful. You can also see my StackOverflow answer <a href="https://stackoverflow.com/questions/56950661/error-more-than-one-package-matched-with-specified-pattern-azure-function-relea/56950662#56950662">here</a>.</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="295" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Release-Dev.png" alt="" class="wp-image-13818" srcset="/wp-content/uploads/2019/07/Release-Dev.png 650w, /wp-content/uploads/2019/07/Release-Dev-300x136.png 300w, /wp-content/uploads/2019/07/Release-Dev-420x190.png 420w, /wp-content/uploads/2019/07/Release-Dev-425x193.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Release Dev</figcaption></figure>



<h2 class="wp-block-heading">Enabling Continuous Deployment</h2>



<p>If you wish you can always enable the continuous delivery or deployment. This will trigger whenever there is a build. To set up this, please go to your Release pipeline and click on the trigger.</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="430" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Contnuous-Delivery-Trigger.png" alt="" class="wp-image-13821" srcset="/wp-content/uploads/2019/07/Contnuous-Delivery-Trigger.png 650w, /wp-content/uploads/2019/07/Contnuous-Delivery-Trigger-300x198.png 300w, /wp-content/uploads/2019/07/Contnuous-Delivery-Trigger-425x281.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Continuous Deployment Trigger</figcaption></figure>



<p>Now you should see an option to enable the Continuous Deployment.</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="499" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Continuous-Deployment-Trigger.png" alt="" class="wp-image-13822" srcset="/wp-content/uploads/2019/07/Continuous-Deployment-Trigger.png 650w, /wp-content/uploads/2019/07/Continuous-Deployment-Trigger-300x230.png 300w, /wp-content/uploads/2019/07/Continuous-Deployment-Trigger-425x326.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Enable Continuous Deployment</figcaption></figure>



<p>Now all you have to is change something in the code, and not worry about the build and releases. How cool that is?</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>In this article, we have learned,</p>



<ul class="wp-block-list"><li>How to configure Build Pipeline Configuration for Azure Function in Azure DevOps</li><li> How to configure Release Pipeline Configuration for Azure Function in Azure DevOps </li><li>About fixing errors in Pipeline configurations in Azure DevOps</li><li>How to enable Continuous Delivery/Deployment in Azure DevOps</li><li>How to enable Continuous Integration in Azure DevOps</li></ul>



<p>Please let me know what else you had learned from this Article.</p>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/azure-function-build-and-release-pipeline-in-azure-devops-ci-cd/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Secure Serverless Azure Functions AppSetting Using Key Vault</title>
		<link>https://sibeeshpassion.com/secure-serverless-azure-functions-appsetting-using-key-vault/</link>
					<comments>https://sibeeshpassion.com/secure-serverless-azure-functions-appsetting-using-key-vault/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Fri, 05 Jul 2019 16:19:46 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Azure App Settings]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[Azure Key Vault]]></category>
		<category><![CDATA[Read Key Vault Settings]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Use Key Vault in Azure Function]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13769</guid>

					<description><![CDATA[[toc] Introduction Security is something that we all are worried about, especially if your applications are in cloud. If someone is able to see the credentials or client&#8217;s data, then you lose the trust you have with your customer. I know, that no one likes it. Fortunately, every cloud providers have already provided enough options to make your application safe and secure. Here, in this post, we are going to discuss about such a feature in Microsoft Azure. I hope you have already used Azure Functions, if you have not, I strongly recommend you to see some related articles here. [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>Security is something that we all are worried about, especially if your applications are in cloud. If someone is able to see the credentials or client&#8217;s data, then you lose the trust you have with your customer. I know, that no one likes it. Fortunately, every cloud providers have already provided enough options to make your application safe and secure. Here, in this post, we are going to discuss about such a feature in Microsoft Azure. I hope you have already used Azure Functions, if you have not, I strongly recommend you to see some related articles <a href="https://sibeeshpassion.com/tag/azure-function/">here</a>. Here in this article, we will see how we can get the connection strings from Azure Key Vault and use it in our Azure Function instead of using it from the usual App Settings. Sounds interesting? So, let us do it. </p>



<h2 class="wp-block-heading">Prerequisites</h2>



<p>It would be great if are familiar with the preceding topics.</p>



<ul class="wp-block-list"><li>Microsoft Azure</li><li>Server less</li><li>C#, or any other programming languages</li></ul>



<p>You should have a valid Azure Subscription to follow along.</p>



<h2 class="wp-block-heading">Background</h2>



<p>As I was explaining, we are going to change the way we take the connection strings and other values in our Azure Function.  Below is my Azure Function sample code.</p>



<script src="https://gist.github.com/SibeeshVenu/c0fd8497a8a86b55921da4679bbc101d.js"></script>



<p>As you can see that this function has custom binding with my service bus as it uses  ServiceBusTrigger. The connection string name is  ServiceBusConnectionString  which we have already set in the Azure Function configuration.</p>



<figure class="wp-block-image"><img decoding="async" width="910" height="732" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Azure-Function-Configuration.png" alt="" class="wp-image-13770" srcset="/wp-content/uploads/2019/07/Azure-Function-Configuration.png 910w, /wp-content/uploads/2019/07/Azure-Function-Configuration-300x241.png 300w, /wp-content/uploads/2019/07/Azure-Function-Configuration-768x618.png 768w, /wp-content/uploads/2019/07/Azure-Function-Configuration-425x342.png 425w" sizes="(max-width: 910px) 100vw, 910px" /><figcaption>Azure Function Configuration</figcaption></figure>



<p>You should be able to see all of your configurations and application settings once you click on the configuration tab.</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="834" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Azure-Function-All-Application-Settings.png" alt="" class="wp-image-13773" srcset="/wp-content/uploads/2019/07/Azure-Function-All-Application-Settings.png 650w, /wp-content/uploads/2019/07/Azure-Function-All-Application-Settings-234x300.png 234w, /wp-content/uploads/2019/07/Azure-Function-All-Application-Settings-425x545.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Azure Function All Application Settings</figcaption></figure>



<p>Here in this post, we are going to change the value of ServiceBusConnectionString to the AzureKey Vault reference. This connection string is given by the customer, isn&#8217;t it always better to make it as secured as possible?</p>



<h2 class="wp-block-heading">Configure Azure Key Vault</h2>



<p>To get start, we should create an Azure Key Vault, please go to your Azure Portal and search with the keyword Key Vaults.</p>



<p>Once you had filled all the required information in the form, you can click on the create button.</p>



<figure class="wp-block-image"><img decoding="async" width="586" height="988" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Create-Key-Vault.png" alt="" class="wp-image-13774" srcset="/wp-content/uploads/2019/07/Create-Key-Vault.png 586w, /wp-content/uploads/2019/07/Create-Key-Vault-178x300.png 178w, /wp-content/uploads/2019/07/Create-Key-Vault-326x550.png 326w" sizes="(max-width: 586px) 100vw, 586px" /><figcaption>Create Azure Key Vault</figcaption></figure>



<p>If you are getting an error as shown in the image below, you should go to the Resource Provider section of your Subscription and then search for Microsoft.KeyValut and then click on register. </p>



<figure class="wp-block-image"><img decoding="async" width="624" height="513" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Subscription-Resource-Provider-Error.png" alt="" class="wp-image-13772" srcset="/wp-content/uploads/2019/07/Subscription-Resource-Provider-Error.png 624w, /wp-content/uploads/2019/07/Subscription-Resource-Provider-Error-300x247.png 300w, /wp-content/uploads/2019/07/Subscription-Resource-Provider-Error-425x349.png 425w" sizes="(max-width: 624px) 100vw, 624px" /><figcaption>Subscription Resource Provider Error</figcaption></figure>



<p>The key vault should be deployed in few seconds or minutes. Now you can go to your Key Vault. You can add Keys, Secrets, Certificates etc to your Key Vaults. But in this post, we are going to add a new Secret for our connection string. Click on the Secrets blade and then click on Generate/Import button. Now let us give all the details as shown in the below image. </p>



<figure class="wp-block-image"><img decoding="async" width="789" height="833" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Create-Secret-in-Azure-Key-Vault.png" alt="" class="wp-image-13775" srcset="/wp-content/uploads/2019/07/Create-Secret-in-Azure-Key-Vault.png 789w, /wp-content/uploads/2019/07/Create-Secret-in-Azure-Key-Vault-284x300.png 284w, /wp-content/uploads/2019/07/Create-Secret-in-Azure-Key-Vault-768x811.png 768w, /wp-content/uploads/2019/07/Create-Secret-in-Azure-Key-Vault-425x449.png 425w" sizes="(max-width: 789px) 100vw, 789px" /><figcaption>Create Secret in Azure Key Vault</figcaption></figure>



<h2 class="wp-block-heading">Set Key Vault Access Policy</h2>



<p>It is great that we have a Key Vault and secret, now we can give permission to our Azure Function application to retrieve this secrets from the Key Vault. But before you do that, you need to add a managed identity to the Azure Function. </p>



<h3 class="wp-block-heading">Add a System Assigned Managed Identity to the Azure Function</h3>



<p>To create an identity, please go to the Platform Features of your Azure Function and click on Identity.</p>



<figure class="wp-block-image"><img decoding="async" width="651" height="408" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Identity-Option-in-Azure-Function.png" alt="" class="wp-image-13781" srcset="/wp-content/uploads/2019/07/Identity-Option-in-Azure-Function.png 651w, /wp-content/uploads/2019/07/Identity-Option-in-Azure-Function-300x188.png 300w, /wp-content/uploads/2019/07/Identity-Option-in-Azure-Function-425x266.png 425w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Identity Option in Azure Function</figcaption></figure>



<p>Now let&#8217;s enable the System Assigned Identity.</p>



<figure class="wp-block-image"><img decoding="async" width="633" height="580" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Assign-System-Assigned-Identity.png" alt="" class="wp-image-13782" srcset="/wp-content/uploads/2019/07/Assign-System-Assigned-Identity.png 633w, /wp-content/uploads/2019/07/Assign-System-Assigned-Identity-300x275.png 300w, /wp-content/uploads/2019/07/Assign-System-Assigned-Identity-425x389.png 425w" sizes="(max-width: 633px) 100vw, 633px" /><figcaption>Assign System Assigned Identity</figcaption></figure>



<h3 class="wp-block-heading">Add Access Control</h3>



<p>To give the access policy, <a href="https://docs.microsoft.com/en-us/azure/key-vault/key-vault-secure-your-key-vault#data-plane-and-access-policies">first we should add a role assignment</a> with contributor role for our application. Now we should also be able to add new role assignment. To do so, go to the Access Control section of your Key Vault and click on Add a role assignment blade. </p>



<figure class="wp-block-image"><img decoding="async" width="482" height="1024" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Add-Role-Assignment-Option-482x1024.png" alt="" class="wp-image-13828" srcset="/wp-content/uploads/2019/07/Add-Role-Assignment-Option-482x1024.png 482w, /wp-content/uploads/2019/07/Add-Role-Assignment-Option-141x300.png 141w, /wp-content/uploads/2019/07/Add-Role-Assignment-Option-259x550.png 259w, /wp-content/uploads/2019/07/Add-Role-Assignment-Option.png 650w" sizes="(max-width: 482px) 100vw, 482px" /></figure>



<h3 class="wp-block-heading">Add Access Policy</h3>



<p>Now that we have created a managed identity and a role assignment,  we should be able to add the Access Polity in the Key Vault for our Azure Function. Go to your Key Vault and click on Access Policies and then click on Add new blade. </p>



<figure class="wp-block-image"><img decoding="async" width="600" height="866" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Add-Access-Policy-With-Managed-Service-Identity-Created-Option.png" alt="" class="wp-image-13830" srcset="/wp-content/uploads/2019/07/Add-Access-Policy-With-Managed-Service-Identity-Created-Option.png 600w, /wp-content/uploads/2019/07/Add-Access-Policy-With-Managed-Service-Identity-Created-Option-208x300.png 208w, /wp-content/uploads/2019/07/Add-Access-Policy-With-Managed-Service-Identity-Created-Option-381x550.png 381w" sizes="(max-width: 600px) 100vw, 600px" /></figure>



<p>Please makes sure to use the, Object ID of the System Assigned Manged Identity that we have already created, here in the Select Principal column. This will make sure that our Azure Function has access to get the value from the Azure Key Vault.</p>



<p>At the end, you should have access policies as below. </p>



<figure class="wp-block-image"><img decoding="async" width="651" height="379" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/All-Access-Policies.png" alt="" class="wp-image-13831" srcset="/wp-content/uploads/2019/07/All-Access-Policies.png 651w, /wp-content/uploads/2019/07/All-Access-Policies-300x175.png 300w, /wp-content/uploads/2019/07/All-Access-Policies-425x247.png 425w" sizes="(max-width: 651px) 100vw, 651px" /></figure>



<h2 class="wp-block-heading">Use the Key Vault Secret in Azure Function</h2>



<p>Now that we have created our secret, and set up the access policy, we can get the secret identifier, to get this, please click on the secret you had created and then version. You should see a window as below.</p>



<figure class="wp-block-image"><img decoding="async" width="634" height="975" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Secret-Identifier-in-Azure-Key-Vault.png" alt="" class="wp-image-13776" srcset="/wp-content/uploads/2019/07/Secret-Identifier-in-Azure-Key-Vault.png 634w, /wp-content/uploads/2019/07/Secret-Identifier-in-Azure-Key-Vault-195x300.png 195w, /wp-content/uploads/2019/07/Secret-Identifier-in-Azure-Key-Vault-358x550.png 358w" sizes="(max-width: 634px) 100vw, 634px" /><figcaption>Secret Identifier in Azure Key Vault</figcaption></figure>



<p>The good thing is you can even provide the activation date and the expiry date. Isn&#8217;t it handy? Copy the value and then go to the configuration page of your Azure Function and then click on the app settings that you want to change, in my case the app setting with the key ServiceBusConnectionString. Now, you should see an option to edit the value there. Now you can give the value there as below. </p>



<pre class="wp-block-code"><code>@Microsoft.KeyVault(SecretUri=Secret URI with version)</code></pre>



<figure class="wp-block-image"><img decoding="async" width="651" height="116" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Add-App-Setting-from-Key-Vault.png" alt="" class="wp-image-13780" srcset="/wp-content/uploads/2019/07/Add-App-Setting-from-Key-Vault.png 651w, /wp-content/uploads/2019/07/Add-App-Setting-from-Key-Vault-300x53.png 300w, /wp-content/uploads/2019/07/Add-App-Setting-from-Key-Vault-425x76.png 425w" sizes="(max-width: 651px) 100vw, 651px" /></figure>



<p>Remember to save the changes and you get the notification as &#8221; Successfully updated web app settings &#8220;. That&#8217;s it. Now you should be able to run your Azure Functions, the only difference is that we are getting the app settings value from the Key Vault. </p>



<p>By chance if you get an error as &#8220;<a href="https://stackoverflow.com/questions/56904926/the-function-runtime-is-unable-to-start-microsoft-azure-servicebus-value-for-t">The function runtime is unable to start. Microsoft.Azure.ServiceBus: Value for the connection string parameter name &#8216;@Microsoft.KeyVault</a>&#8220;, please make sure that the <a href="https://docs.microsoft.com/en-us/azure/app-service/app-service-key-vault-references#reference-syntax">right format</a> <strong>@Microsoft.KeyVault(SecretUri=Secret URI with version)</strong> in the Value column.</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="458" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Azure-Function-Key-Vault-Error.png" alt="" class="wp-image-13778" srcset="/wp-content/uploads/2019/07/Azure-Function-Key-Vault-Error.png 650w, /wp-content/uploads/2019/07/Azure-Function-Key-Vault-Error-300x211.png 300w, /wp-content/uploads/2019/07/Azure-Function-Key-Vault-Error-425x299.png 425w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Azure Function Key Vault Error</figcaption></figure>



<p>Or if you get any error as &#8220;<a href="https://stackoverflow.com/questions/40298883/value-cannot-be-null-parameter-name-uristring/56906284#56906284">Value can not be null. Parameter name: uriString</a>&#8220;, please make sure that you have done the Access Policy configuration correctly. </p>



<figure class="wp-block-image"><img decoding="async" width="688" height="316" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Secret-Error.png" alt="" class="wp-image-13789" srcset="/wp-content/uploads/2019/07/Secret-Error.png 688w, /wp-content/uploads/2019/07/Secret-Error-300x138.png 300w, /wp-content/uploads/2019/07/Secret-Error-425x195.png 425w" sizes="(max-width: 688px) 100vw, 688px" /><figcaption>Secret Error</figcaption></figure>



<h2 class="wp-block-heading">Run Azure Function</h2>



<p>Now you can go to your Azure Functions and try to run any one of them which uses the app settings that we have configured. If everything is fine, you should be able to run the Function and should get some responses. </p>



<figure class="wp-block-image"><img decoding="async" width="650" height="580" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Azure-Function-Run-Result.png" alt="" class="wp-image-13832" srcset="/wp-content/uploads/2019/07/Azure-Function-Run-Result.png 650w, /wp-content/uploads/2019/07/Azure-Function-Run-Result-300x268.png 300w, /wp-content/uploads/2019/07/Azure-Function-Run-Result-425x379.png 425w" sizes="(max-width: 650px) 100vw, 650px" /></figure>



<h2 class="wp-block-heading">Conclusion</h2>



<p>In this article, we have learned,</p>



<ul class="wp-block-list"><li>About Azure Function and it&#8217;s configuration</li><li>How to configure Azure Key Vault</li><li>How to set Managed Identity for an Azure Function application</li><li>How to create Role Assignments in Key Vault Access Control</li><li>How to create Access policies for the managed identity</li><li>How to use Azure Key vault secret in the Azure Function app settings </li></ul>



<p>Please let me know what else you had learned from this Article.</p>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/secure-serverless-azure-functions-appsetting-using-key-vault/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Realtime IoT Data using Azure SignalR and Functions in Angular</title>
		<link>https://sibeeshpassion.com/realtime-iot-data-using-azure-signalr-and-functions-in-angular/</link>
					<comments>https://sibeeshpassion.com/realtime-iot-data-using-azure-signalr-and-functions-in-angular/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 31 Dec 2018 21:04:26 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[Azure IoT]]></category>
		<category><![CDATA[Http Trigger]]></category>
		<category><![CDATA[IoT Dev Kit]]></category>
		<category><![CDATA[IoT Hub]]></category>
		<category><![CDATA[IoT Hub Trigger]]></category>
		<category><![CDATA[MXChip]]></category>
		<category><![CDATA[Serverless]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13498</guid>

					<description><![CDATA[[toc] Introduction The data coming from the IoT devices are to be shown in real time, if we failed to do that, then there is no point in showing it. Here in this article, we will see how we can show the real-time data from our IoT device in an Angular application using Azure SignalR service and Azure Functions. Sounds interesting? So the flow of data can be defined as IoT device -&#62; Azure IoT Hub -&#62; Azure Function -&#62; Azure SignalR Service -&#62; Angular application. Sounds interesting? Let&#8217;s start then. Background In our previous article, we have already created [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>The data coming from the <a href="https://sibeeshpassion.com/category/iot/">IoT</a> devices are to be shown in real time, if we failed to do that, then there is no point in showing it. Here in this article, we will see how we can show the real-time data from our IoT device in an Angular application using Azure SignalR service and Azure Functions. Sounds interesting? So the flow of data can be defined as IoT device -&gt; Azure IoT Hub -&gt; Azure Function -&gt; Azure SignalR Service -&gt; Angular application. Sounds interesting? Let&#8217;s start then.</p>



<h2 class="wp-block-heading">Background</h2>



<p> In our previous article, we have already created an <a href="https://sibeeshpassion.com/iothubtrigger-azure-function-and-azure-iot-hub/">Azure Function which pulls the Data from our IoT Hub</a> whenever there is any new messages/events happening. If you have not read the same, please read it. </p>



<h2 class="wp-block-heading">Source Code</h2>



<p>Please feel free to fork, clone this project from GitHub here: <strong><a href="https://github.com/SibeeshVenu/Realtime-IoT-Device-Data-using-Azure-SignalR-and-Azure-Function-in-Angular">Realtime-IoT-Device-Data-using-Azure-SignalR-and-Azure-Function-in-Angular</a></strong></p>



<h2 class="wp-block-heading">Real-time IoT Data Processing</h2>



<p>We will be creating two solutions, one for Angular application and one for Azure Functions. We will also create a new Azure Signal R service in the Azure portal. </p>



<h3 class="wp-block-heading">Azure SignalR Service</h3>



<p>According to Microsoft,  Azure SignalR Service is an Azure managed PaaS service to simplify the development, deployment, and management of real-time web application using SignalR, with Azure supported SLA, scaling, performance, and security. The service provides API/SDK/CLI/UI, and the <g class="gr_ gr_5 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" id="5" data-gr-id="5">rich</g> set of code samples, templates, and demo applications.</p>



<p>Core features for Azure SignalR Service:</p>



<ul class="wp-block-list"><li>Native ASP.NET Core SignalR development support</li><li>ASP.NET Core SignalR backend for improved performance and stability</li><li>Redis based backplane scaling</li><li>Web Socket, comet, and .NET Server-Sent-Event support</li><li>REST API support for server broadcast scenarios</li><li>Resource Provider support for ARM Template based CLI</li><li>Dashboard for performance and connection monitoring</li><li>Token-based AUTH model</li></ul>



<p> Let&#8217;s log in to our Azure portal and create a new Azure Signal R service. Click on the +Create a resource and search SignalR Service.  Once you have created the service, go to the keys section and copy the connection string, we will be using the same in our Azure Function.</p>



<h3 class="wp-block-heading">Azure Functions</h3>



<p>As we discussed in my previous article, we will be creating an Azure Function with an IoTHubTrigger in it. You can refer to <a href="https://sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/#creating-an-azure-function-solution-and-function">this article</a> for the hints on how to create an Azure Function solution in Visual Studio. Please make sure that you had installed the required packages as mentioned in the image below.</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="390" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Required-Packages.jpg" alt="" class="wp-image-13507" srcset="/wp-content/uploads/2018/12/Required-Packages.jpg 650w, /wp-content/uploads/2018/12/Required-Packages-300x180.jpg 300w, /wp-content/uploads/2018/12/Required-Packages-400x240.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Required Packages</figcaption></figure>



<p>Once you have created a new Function in the solution it is time to add some code.</p>



<pre class="wp-block-code"><code>using Microsoft.Azure.EventHubs;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.SignalRService;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Text;
using System.Threading.Tasks;
using IoTHubTrigger = Microsoft.Azure.WebJobs.EventHubTriggerAttribute;

namespace AzureFunction
{
    public static class SignalR
    {
        [FunctionName("SignalR")]
        public static async Task Run(
            [IoTHubTrigger("messages/events", Connection = "IoTHubTriggerConnection", ConsumerGroup = "ml-iot-platform-func")]EventData message,
            [SignalR(HubName = "broadcast")]IAsyncCollector&lt;SignalRMessage> signalRMessages,
            ILogger log)
        {
            var deviceData = JsonConvert.DeserializeObject&lt;DeviceData>(Encoding.UTF8.GetString(message.Body.Array));
            deviceData.DeviceId = Convert.ToString(message.SystemProperties["iothub-connection-device-id"]);


            log.LogInformation($"C# IoT Hub trigger function processed a message: {JsonConvert.SerializeObject(deviceData)}");
            await signalRMessages.AddAsync(new SignalRMessage()
            {
                Target = "notify",
                Arguments = new[] { JsonConvert.SerializeObject(deviceData) }
            });
        }
    }
}</code></pre>



<p>As you can see we are using Microsoft.Azure.WebJobs.EventHubTriggerAttribute for pulling data from our IoT Hub. Here &#8220;messages/events&#8221; is our Event Hub Name and Connection is the IoT Hub connections string which is defined in the local.settings.json file and the ConsumerGroup is the group I have created for the Azure Function solution. </p>



<p>If you have noticed, we are using the HubName as &#8220;broadcast&#8221; in the SignalR attribute and &#8220;notify&#8221; as the SignalR message Target property. If you change the Target property, you may get a warning in your browser console as &#8220;Warning: No client method with the name &#8216;notify&#8217; found.&#8221;. The   @aspnet/<g class="gr_ gr_113 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="113" data-gr-id="113">signalr</g> package is checking for the Target property &#8216;notify&#8217; by default. </p>



<figure class="wp-block-image"><img decoding="async" width="650" height="202" src="https://sibeeshpassion.com/wp-content/uploads/2019/01/Nofity-not-found-error.jpg" alt="" class="wp-image-13517" srcset="/wp-content/uploads/2019/01/Nofity-not-found-error.jpg 650w, /wp-content/uploads/2019/01/Nofity-not-found-error-300x93.jpg 300w, /wp-content/uploads/2019/01/Nofity-not-found-error-400x124.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Nofity not found error</figcaption></figure>



<figure class="wp-block-image"><img decoding="async" width="650" height="255" src="https://sibeeshpassion.com/wp-content/uploads/2019/01/HubConnection-Js-File-Looks-for-Notify.jpg" alt="" class="wp-image-13516" srcset="/wp-content/uploads/2019/01/HubConnection-Js-File-Looks-for-Notify.jpg 650w, /wp-content/uploads/2019/01/HubConnection-Js-File-Looks-for-Notify-300x118.jpg 300w, /wp-content/uploads/2019/01/HubConnection-Js-File-Looks-for-Notify-400x157.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>HubConnection Js File Looks for Notify</figcaption></figure>



<p>So, I will keep the Target property as &#8216;notify&#8217;. By default, the message data doesn&#8217;t contain the device id value, so we will have to get the same from SystemProperties.</p>



<pre class="wp-block-code"><code> var deviceData = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(message.Body.Array));
             deviceData.DeviceId = Convert.ToString(message.SystemProperties["iothub-connection-device-id"]);</code></pre>



<p>Below is my DeviceData class.</p>



<pre class="wp-block-code"><code>using Newtonsoft.Json;
using System;

namespace AzureFunction
{
    public class DeviceData
    {
        [JsonProperty("messageId")]
        public string MessageId { get; set; }

        [JsonProperty("deviceId")]
        public string DeviceId { get; set; }

        [JsonProperty("temperature")]
        public string Temperature { get; set; }

        [JsonProperty("humidity")]
        public string Humidity { get; set; }

        [JsonProperty("pressure")]
        public string pressure { get; set; }

        [JsonProperty("pointInfo")]
        public string PointInfo { get; set; }

        [JsonProperty("ioTHub")]
        public string IoTHub { get; set; }

        [JsonProperty("eventEnqueuedUtcTime")]
        public DateTime EventEnqueuedUtcTime { get; set; }

        [JsonProperty("eventProcessedUtcTime")]
        public DateTime EventProcessedUtcTime { get; set; }

        [JsonProperty("partitionId")]
        public string PartitionId { get; set; }
    }
}</code></pre>



<p>When you work with any client like Angular application, it is important that we need to get the token/connection from the server, so that the client can persist the connection with the <g class="gr_ gr_6 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" id="6" data-gr-id="6">server</g>, hence the data can be pushed to the client from SignalR service. So, we will create a new Azure Function which will return the connection information with the Url and AccessToken.</p>



<pre class="wp-block-code"><code>using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.SignalRService;
using Microsoft.Extensions.Logging;

namespace AzureFunction
{
    public static class SignalRConnection
    {
        [FunctionName("SignalRConnection")]
        public static SignalRConnectionInfo Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            [SignalRConnectionInfo(HubName = "broadcast")] SignalRConnectionInfo info,
            ILogger log) => info;
    }
}</code></pre>



<p>Please make sure that you have set AuthorizationLevel.Anonymous in HttpTrigger attribute and also to use the same HubName we have used for our other Azure Function, which is SignalR. </p>



<p>Now we can customize our local.settings.json file.</p>



<pre class="wp-block-code"><code>{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "AzureSignalRConnectionString": "",
    "MSDEPLOY_RENAME_LOCKED_FILES": 1,
    "IoTHubTriggerConnection": ""
  },
  "Host": {
    "LocalHttpPort": 7071,
    "CORS": "*"
  }
}</code></pre>



<p>Please be noted that this file if for local configuration and remember to change the connections strings here before you run the application. If you want to enable the CORS in the Azure Function in the Azure Portal, you can do that by following the steps mentioned in the image below.</p>



<figure class="wp-block-image"><img decoding="async" width="649" height="227" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Enabling-CORS-in-Azure-Function.jpg" alt="" class="wp-image-13499" srcset="/wp-content/uploads/2018/12/Enabling-CORS-in-Azure-Function.jpg 649w, /wp-content/uploads/2018/12/Enabling-CORS-in-Azure-Function-300x105.jpg 300w, /wp-content/uploads/2018/12/Enabling-CORS-in-Azure-Function-400x140.jpg 400w" sizes="(max-width: 649px) 100vw, 649px" /><figcaption>Enabling CORS in Azure Function</figcaption></figure>



<h3 class="wp-block-heading">Angular Client</h3>



<p>As we have already created our Azure Functions, now it is time to create our Angular client. Let&#8217;s use Angular CLI and create a new project. Now we can add a new package <em>@aspnet/</em><g class="gr_ gr_308 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace" id="308" data-gr-id="308"><em class="">signalr</em></g> to our application which will help us to talk to our Azure SignalR service. </p>



<h4 class="wp-block-heading"> home.component.ts </h4>



<p>Below is my code for home.component.ts file.</p>



<pre class="wp-block-code"><code>import { Component, OnInit, NgZone } from '@angular/core';
import { SignalRService } from 'src/app/services/signal-r.service';
import { StreamData } from 'src/app/models/stream.data';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
  streamData: StreamData = new StreamData();

  constructor(private signalRService: SignalRService) {
  }

  ngOnInit() {
    this.signalRService.init();
    this.signalRService.mxChipData.subscribe(data => {
      this.streamData = JSON.parse(data);
      console.log(data);
    });
  }
}</code></pre>



<h4 class="wp-block-heading"> home.component.html </h4>



<p>We use Material card to show the Device data, so we can define our home.component.html file as preceding.</p>



<pre class="wp-block-code"><code>&lt;div class="container">
  &lt;div class="row">
    &lt;mat-card class="example-card">
      &lt;mat-card-header>
        &lt;div mat-card-avatar class="example-header-image">&lt;/div>
        &lt;mat-card-title>Real Time Values&lt;/mat-card-title>
        &lt;mat-card-subtitle>The real time values of humidity, temprature etc...&lt;/mat-card-subtitle>
      &lt;/mat-card-header>
      &lt;mat-card-content>
        &lt;p>
          &lt;label>DeviceId: &lt;/label>
          {{streamData?.deviceId}}
        &lt;/p>
        &lt;p>
          &lt;label>Temperature: &lt;/label>
          {{streamData?.temperature}}
        &lt;/p>
        &lt;p>
          &lt;label>Humidity: &lt;/label>
          {{streamData?.humidity}}
        &lt;/p>
      &lt;/mat-card-content>
    &lt;/mat-card>
  &lt;/div>
&lt;/div></code></pre>



<h4 class="wp-block-heading">signal-r.service.ts</h4>



<p>Now, we can create a new service which calls our Azure SignalR service. </p>



<pre class="wp-block-code"><code>import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, Subject } from 'rxjs';
import { SignalRConnection } from '../models/signal-r-connection.model';
import { environment } from '../../environments/environment';
import * as SignalR from '@aspnet/signalr';

@Injectable({
  providedIn: 'root'
})

export class SignalRService {
  mxChipData: Subject&lt;string> = new Subject();
  private hubConnection: SignalR.HubConnection;

  constructor(private http: HttpClient) {
  }

  private getSignalRConnection(): Observable&lt;SignalRConnection> {
    return this.http.get&lt;SignalRConnection>(`${environment.baseUrl}SignalRConnection`);
  }

  init() {
    this.getSignalRConnection().subscribe(con => {
      const options = {
        accessTokenFactory: () => con.accessToken
      };

      this.hubConnection = new SignalR.HubConnectionBuilder()
        .withUrl(con.url, options)
        .configureLogging(SignalR.LogLevel.Information)
        .build();

      this.hubConnection.start().catch(error => console.error(error));

      this.hubConnection.on('notify', data => {
        this.mxChipData.next(data);
      });
    });
  }
}</code></pre>



<p>As you can see, we are doing the following things in our service.</p>



<ol class="wp-block-list"><li>Get the SignalR connection information which contains Url and Access token, by calling the SignalRConnection Azure Function.</li><li>Create the Hub connection using SignalR.HubConnectionBuilder.</li><li>Start the Hub connection</li><li>Wire the &#8216;notify&#8217; function, remember we have set this in our Azure Function SignalR.</li></ol>



<h4 class="wp-block-heading">signal-r-connection.model.ts</h4>



<pre class="wp-block-code"><code>export class SignalRConnection {
   url: string;
   accessToken: string;
}</code></pre>



<h4 class="wp-block-heading">stream.data.ts</h4>



<pre class="wp-block-code"><code>export class StreamData {
    messageId: string;
    deviceId: string;
    temperature: string;
    humidity: string;
    pressure: string;
    pointInfo: string;
    ioTHub: string;
    eventEnqueuedUtcTime: string;
    eventProcessedUtcTime: string;
    partitionId: string;
}</code></pre>



<h2 class="wp-block-heading">Output</h2>



<p>Now, let&#8217;s just run our Angular application, Azure Function, and a simulated device. Please refer to <a href="https://sibeeshpassion.com/an-introduction-to-azure-stream-analytics-job/#run-the-stream-analytics-job-and-see-the-data-in-the-database">this link</a> for the information related to the Simulated device. Please feel free to connect to your IoT device, if you haven&#8217;t configured the simulated device. </p>



<figure class="wp-block-image"><img decoding="async" width="1280" height="720" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Realtime-IoT-Device-Data.gif" alt="" class="wp-image-13501"/><figcaption>Realtime IoT Device Data</figcaption></figure>



<figure class="wp-block-image"><img decoding="async" width="650" height="250" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Serverless-Realtime-MXChip-Data-Angular.gif" alt="Serverless Realtime MXChip Data Angular" class="wp-image-13512"/><figcaption>Serverless Realtime MXChip Data Angular</figcaption></figure>



<p>References</p>



<ol class="wp-block-list"><li><a href="https://medium.com/medialesson/serverless-real-time-messaging-with-azure-functions-and-azure-signalr-service-c70e781ff3c3">Server less real-time messaging</a></li></ol>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Wow!. Now we have learned,</p>



<ul class="wp-block-list"><li>How to connect IoT Hub and Azure Function </li><li>What is Triggers in Azure Function</li><li>How to connect Azure Function and Azure SignalR service</li><li>How to post data to Azure SignalR service</li><li>How to connect Azure SignalR service from Angular client</li><li>How to show <g class="gr_ gr_377 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="377" data-gr-id="377">real time</g> data in Angular application from IoT device</li></ul>



<p>You can always ready my IoT articles&nbsp;<a href="https://sibeeshpassion.com/category/iot/">here</a>.</p>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/realtime-iot-data-using-azure-signalr-and-functions-in-angular/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>IoTHubTrigger Azure Function and Azure IoT Hub</title>
		<link>https://sibeeshpassion.com/iothubtrigger-azure-function-and-azure-iot-hub/</link>
					<comments>https://sibeeshpassion.com/iothubtrigger-azure-function-and-azure-iot-hub/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Thu, 27 Dec 2018 11:47:52 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[Azure IoT]]></category>
		<category><![CDATA[codeproject]]></category>
		<category><![CDATA[IoT Hub]]></category>
		<category><![CDATA[IoTHubTrigger]]></category>
		<category><![CDATA[MXChip]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13494</guid>

					<description><![CDATA[[toc] Introduction For the past few days I am playing with my MXChip and had written some articles about the same, you should be able to find those here. Here in this article, we will send some data to our Azure IoT hub and we will connect an Azure Function with our IoT Hub using IoTHubTrigger Event Hub Trigger Attribute. If you are ready, let&#8217;s do this. Background As I said this article is part of my IoT article series, so if you have read my previous articles on this topic, it may be easier for you to understand the [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>For the past few days I am playing with my MXChip and had written some articles about the same, you should be able to find those <a href="https://sibeeshpassion.com/category/iot/">here</a>. Here in this article, we will send some data to our Azure IoT hub and we will connect an Azure Function with our IoT Hub using IoTHubTrigger Event Hub  Trigger Attribute. If you are ready, let&#8217;s do this. </p>



<h2 class="wp-block-heading">Background</h2>



<p>As I said this article is part of my IoT article series, so if you have read my previous articles on this topic, it may be easier for you to understand the concept. Before you start this article, please make sure that you had already created an Azure IoT hub and it is running. You can always send the messages to this IoT Hub either by connecting the actual device, let&#8217;s say an MXChip or using a simulating device.</p>



<h2 class="wp-block-heading">IoTHubTrigger Demo</h2>



<h3 class="wp-block-heading">Creating an Azure Function App</h3>



<p>I am going to create an Azure Function App in Visual Studio, if you are not sure about how we can create and publish the Azure Function, please read <a href="https://sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/#play-with-azure-function">this section</a> of my previous article. Let&#8217;s create a new solution now. </p>



<figure class="wp-block-image"><img decoding="async" width="650" height="375" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/IoTHubTrigger.jpg" alt="" class="wp-image-13495" srcset="/wp-content/uploads/2018/12/IoTHubTrigger.jpg 650w, /wp-content/uploads/2018/12/IoTHubTrigger-300x173.jpg 300w, /wp-content/uploads/2018/12/IoTHubTrigger-400x231.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>IoTHubTrigger</figcaption></figure>



<p>Once you click OK, a new Azure Function will be generated for you with some initial codes in it. Let&#8217;s edit the Function as below.</p>



<pre class="wp-block-code"><code>using Microsoft.Azure.EventHubs;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System.Text;
using IoTHubTrigger = Microsoft.Azure.WebJobs.EventHubTriggerAttribute;

namespace IoTHubTrigger_Azure_Function_and_Azure_IoT_Hub
{
    public static class IoTHubFunc
    {
        [FunctionName("IoTHubData")]
        public static void Run(
            [IoTHubTrigger("messages/events", Connection = "IoTHubTriggerConnection", ConsumerGroup ="FuncGroup")]EventData message, 
            ILogger log)
        {
            log.LogInformation($"C# IoT Hub trigger function processed a message: {Encoding.UTF8.GetString(message.Body.Array)}");
        }
    }
}</code></pre>



<p>Here the IoTHubTriggerConnection is the connection string we are providing in the local.settings.json file. The consumer group will come into the play if you have many applications which need to be receiving the data from your IoT Hub. Below is the class definition of EventHubTriggerAttribute.</p>



<pre class="wp-block-code"><code>public sealed class EventHubTriggerAttribute : Attribute
    {
        public EventHubTriggerAttribute(string eventHubName);

        public string EventHubName { get; }
        public string ConsumerGroup { get; set; }
        public string Connection { get; set; }
    }</code></pre>



<h3 class="wp-block-heading">Send data to the Azure IoT Hub</h3>



<p>As I mentioned earlier, there are two ways you can send the data to the Azure IoT Hub.</p>



<ol class="wp-block-list"><li>Using a device, for example, MXChip </li><li><a href="https://sibeeshpassion.com/an-introduction-to-azure-stream-analytics-job/#run-the-stream-analytics-job-and-see-the-data-in-the-database">Simulated device</a></li></ol>



<p>Once the data is been sending, you can see the message received count in Azure IoT Hub in the overview section. </p>



<h3 class="wp-block-heading">Run the Azure Function</h3>



<p>So, the IoT Hub is started receiving the messages from the device, and now we can use our Azure Function to pull the data from the IoT hub with the help of IoT hub Trigger. Run your Function App, Simulated Device application and see the output. </p>



<figure class="wp-block-image"><img decoding="async" width="650" height="484" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/IoTHubTrigger-Demo-WIth-Simulated-App.jpg" alt="" class="wp-image-13496" srcset="/wp-content/uploads/2018/12/IoTHubTrigger-Demo-WIth-Simulated-App.jpg 650w, /wp-content/uploads/2018/12/IoTHubTrigger-Demo-WIth-Simulated-App-300x223.jpg 300w, /wp-content/uploads/2018/12/IoTHubTrigger-Demo-WIth-Simulated-App-400x298.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>IoT Hub Trigger Output </figcaption></figure>



<p>As you can see in the output, our Azure Function app is receiving the data from Azure IoT hub instantly. Now you can perform any actions with this data. I will leave that to you.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Wow!. Now we have learned,</p>



<ul class="wp-block-list"><li>Usage of Azure IoT Hub Trigger in Azure Function</li><li>Creating Azure Function App</li><li>See the Data from Azure IoT Hub in the Azure Function App</li></ul>



<p>You can always ready my IoT articles&nbsp;<a href="https://sibeeshpassion.com/category/iot/">here</a>.</p>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/iothubtrigger-azure-function-and-azure-iot-hub/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Azure Function as Output Job Topology of an Azure Stream Analytics Job</title>
		<link>https://sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/</link>
					<comments>https://sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Wed, 19 Dec 2018 14:37:18 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[ASA]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[Azure Function and Azure Stream Analytics]]></category>
		<category><![CDATA[Azure IoT]]></category>
		<category><![CDATA[IoT Hub]]></category>
		<category><![CDATA[MXChip]]></category>
		<category><![CDATA[Stream Analytics Job]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13479</guid>

					<description><![CDATA[[toc] Introduction For the last few days, I am playing with my Azure IoT Dev Kit MXChip. In this article, we are going to see how we can set up an Azure Function as an Output job topology of an Azure Stream Analytics job. Isn&#8217;t that sound interesting? In our previous articles, we have already seen what is an Azure Stream Analytics Job and How can we create in by using the portal and Visual Studio. If you haven&#8217;t read those articles, I strongly recommend you to read. Let&#8217;s jump on to this article now. Background As I have mentioned [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>For the last few days, I am playing with my Azure IoT Dev Kit MXChip. In this article, we are going to see how we can set up an Azure Function as an Output job topology of an Azure Stream Analytics job. Isn&#8217;t that sound interesting? In our previous <a href="https://sibeeshpassion.com/tag/stream-analytics-job/">articles</a>, we have already seen what is an Azure Stream Analytics Job and How can we create in by using the portal and Visual Studio. If you haven&#8217;t read those articles, I strongly recommend you to read. Let&#8217;s jump on to this article now.</p>



<h2 class="wp-block-heading">Background</h2>



<p>As I have mentioned earlier, in this article we will be,&nbsp;</p>



<ol class="wp-block-list"><li>using our existing Azure Stream Analytics job.</li><li>creating a new Azure Function App.</li><li>setting up the newly created Azure function as an output job topology of the stream analytics job.</li><li>monitoring the data coming to the Azure Function from the stream analytics job.</li></ol>



<h2 class="wp-block-heading">Play with Azure Function</h2>



<p>Yeah, we are going to play with it. Let&#8217;s go and create one then.</p>



<h3 class="wp-block-heading">Creating an Azure Function</h3>



<p>To create an Azure Function application, you need to login to your Azure portal and click on the Create a resource icon, and then you can search for the &#8221; Function App&#8221;.&nbsp;</p>



<p>In the next screen, provide the following information.&nbsp;</p>



<ol class="wp-block-list"><li>App Name</li><li>Subscription</li><li>Resource Group</li><li>OS</li><li>Hosting plan</li><li>Location&nbsp;</li><li>Runtime stack</li><li>Storage</li><li>Application Insights</li></ol>



<p>Here the consumption plan hosting plan allows you to pay per execution, and the App service plan allows you to have a predefined capacity. For the runtime stack, we will use .NET, however, you are free to use anything you wish.&nbsp;</p>



<p>Once you have created the same, you should be able to see it under the Function Apps section.&nbsp;</p>



<h3 class="wp-block-heading">Creating an Azure Function Solution and Function</h3>



<p>Now let&#8217;s go to our Visual Studio and create a new solution for our Azure Function.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter is-resized"><img decoding="async" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Function-Project-Type-1024x419.jpg" alt="" class="wp-image-13480" width="512" height="210" srcset="/wp-content/uploads/2018/12/Azure-Function-Project-Type-1024x419.jpg 1024w, /wp-content/uploads/2018/12/Azure-Function-Project-Type-300x123.jpg 300w, /wp-content/uploads/2018/12/Azure-Function-Project-Type-768x314.jpg 768w, /wp-content/uploads/2018/12/Azure-Function-Project-Type-400x163.jpg 400w, /wp-content/uploads/2018/12/Azure-Function-Project-Type.jpg 1375w" sizes="(max-width: 512px) 100vw, 512px" /><figcaption>Azure Function Project Type</figcaption></figure></div>



<p>Now you can right click on your newly created project and add a new HttpTrigger Function. We will keep the Access Rights to Anonymous for now. I have named my function as &#8220;GetData&#8221;. For now, let&#8217;s just get the data from our Stream Analytics job and just check the length.&nbsp;</p>



<pre class="wp-block-code"><code>using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace ml.IoTPlatform.AzureFunctions
{
    public static class GetData
    {
        [FunctionName("GetData")]
        public static async Task&lt;HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post")]HttpRequestMessage req,
            ILogger log)
        {
            log.LogInformation($"GetData function triggered with Uri {req.RequestUri}");

            string content = await req.Content.ReadAsStringAsync();
            log.LogInformation($"String content is {content}");
            dynamic data = JsonConvert.DeserializeObject(content);

            log.LogInformation($"Data count is {data?.Count}");

            if (data?.ToString()?.Length > 262144)
            {
                return new HttpResponseMessage(HttpStatusCode.RequestEntityTooLarge);
            }

            return req.CreateResponse(HttpStatusCode.OK, "Success");
        }
    }
}</code></pre>



<p>As you can see we are not doing nothing much for now, we are just receiving the data as&nbsp;HttpRequestMessage and we are reading the content as&nbsp;req.Content.ReadAsStringAsync() and then deserialize the object. If you are not doing this step, you may get an error as&nbsp;&#8220;<strong>No MediaTypeFormatter is available to read an object of type &#8216;Object&#8217; from content with media type &#8216;application/octet-stream&#8217;.</strong>&#8220;</p>



<p>We are also checking the entity length, and if it is too large we are sending a&nbsp;HttpResponseMessage with status code 413.&nbsp;</p>



<h3 class="wp-block-heading">Publish the Azure Function App</h3>



<p>To publish your Azure Function app, just right click on your project and click Publish and then set up your publish target by choosing the existing Azure Function App, remember we have created on earlier? Once you publish the same, you can go into your Function App and see your Function. You can also test the same with some dummy data.&nbsp;</p>



<p>There are probabilities to get an error as &#8220;<strong>Web Deploy cannot modify the file on the destination because it is locked by an external process</strong>&#8221; when you try to publish your Function App from Visual Studio, while your Function App is running, to fix this you can see my answer <a href="https://stackoverflow.com/questions/37918650/azure-web-app-deploy-web-deploy-cannot-modify-the-file-on-the-destination-becau/53833766#53833766">here</a>.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="284" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Function-App-in-Portal.jpg" alt="" class="wp-image-13481" srcset="/wp-content/uploads/2018/12/Function-App-in-Portal.jpg 651w, /wp-content/uploads/2018/12/Function-App-in-Portal-300x131.jpg 300w, /wp-content/uploads/2018/12/Function-App-in-Portal-400x175.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Function App in Portal</figcaption></figure></div>



<h2 class="wp-block-heading">Azure Stream Analytics Job</h2>



<p>Let&#8217;s go back to our Azure Stream Analytics now as we have already configured our Azure Function App successfully.&nbsp;</p>



<h3 class="wp-block-heading">Configure Azure Function Output</h3>



<p>In my previous <a href="https://sibeeshpassion.com/azure-stream-analytics-job-and-tools-for-visual-studio/">article</a>, we had created an Azure Stream Analytics job solution using Visual Studio, let&#8217;s open that solution now and configure the new output for Azure Function.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="640" height="535" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Solution-Explorer.jpg" alt="" class="wp-image-13482" srcset="/wp-content/uploads/2018/12/Solution-Explorer.jpg 640w, /wp-content/uploads/2018/12/Solution-Explorer-300x251.jpg 300w, /wp-content/uploads/2018/12/Solution-Explorer-400x334.jpg 400w" sizes="(max-width: 640px) 100vw, 640px" /><figcaption>Solution Explorer</figcaption></figure></div>



<p>While configuring the Azure Function Output, please make sure that you are selecting the existing azure function app.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="281" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Function-Output-Configuration.jpg" alt="" class="wp-image-13483" srcset="/wp-content/uploads/2018/12/Azure-Function-Output-Configuration.jpg 651w, /wp-content/uploads/2018/12/Azure-Function-Output-Configuration-300x129.jpg 300w, /wp-content/uploads/2018/12/Azure-Function-Output-Configuration-400x173.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Azure Function Output Configuration</figcaption></figure></div>



<h3 class="wp-block-heading">Update the Script</h3>



<p>We should also do some changes in our Script.asaql file to support our newly created output.&nbsp;</p>



<pre class="wp-block-code"><code>WITH BasicOutput AS 
(
SELECT    
    messageId,
    deviceId,
    temperature,
    humidity,
    pressure,
    pointInfo,
    IoTHub,
    MAX(EventEnqueuedUtcTime) AS EventEnqueuedUtcTime,
    EventProcessedUtcTime,
    PartitionId    
FROM
    Input TIMESTAMP By EventEnqueuedUtcTime
    GROUP BY TUMBLINGWINDOW(second, 10), 
    messageId, 
    deviceId,
    temperature,
    humidity,
    pressure,
    pointInfo,
    IoTHub,
    EventEnqueuedUtcTime,
    EventProcessedUtcTime,
    PartitionId
)

SELECT * INTO SQLServerOutput FROM BasicOutput
SELECT * INTO AzureFunctionOutput FROM BasicOutput</code></pre>



<h3 class="wp-block-heading">Updating the TLS Version</h3>



<p>Once that is done, just click the button Submit to Azure, if you have any doubts in this section, read my previous posts on this topic. Now let&#8217;s log in to the portal again and see all the outputs, inputs, and the query is been published or not.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="220" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Outputs-in-Portal.jpg" alt="" class="wp-image-13484" srcset="/wp-content/uploads/2018/12/Outputs-in-Portal.jpg 651w, /wp-content/uploads/2018/12/Outputs-in-Portal-300x101.jpg 300w, /wp-content/uploads/2018/12/Outputs-in-Portal-400x135.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Outputs in Portal</figcaption></figure></div>



<p>Cool!. Well done, it seems like it is published. Now if you click on the AzureFunctionOutput, you may get a warning as &#8220;<strong>Please make sure that the Minimum TLS version is set to 1.0 on your Azure Functions before you start your ASA job</strong>&#8220;. I would rather treat this as an error instead of a warning because without making this changes our Azure Stream Analytics job will not write to our Azure Function. So this is very important, I spent many hours in this and finally found this was the root cause of my issue, you can see my answer about this <a href="https://stackoverflow.com/questions/53851553/an-error-occurred-send-events-azure-function-output-adapter-failed-to-write-eve/53851554#53851554">here</a>.</p>



<p>So just go to your Azure Function App and click on Platform Features -&gt; SSL -&gt; Minimum TLS Version</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="511" height="397" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Setting-TLS-Version.jpg" alt="" class="wp-image-13485" srcset="/wp-content/uploads/2018/12/Setting-TLS-Version.jpg 511w, /wp-content/uploads/2018/12/Setting-TLS-Version-300x233.jpg 300w, /wp-content/uploads/2018/12/Setting-TLS-Version-400x311.jpg 400w" sizes="(max-width: 511px) 100vw, 511px" /><figcaption>Setting TLS Version</figcaption></figure></div>



<p>There is a saying that developers don&#8217;t care about warning but only the errors, in some cases it is true. Hm, I was just kidding.&nbsp;</p>



<h2 class="wp-block-heading">Output</h2>



<p>Once you are done everything mentioned, you are good to go and start your Stream Analytics job, please make sure that your MXChip is connected to a power source so that the device can start sending the data.&nbsp;</p>



<h3 class="wp-block-heading">Checking the SQL Server Output</h3>



<p>Now let&#8217;s login to our SQL Server Database and run the below query to make sure that we are getting the data from the device.</p>



<pre class="wp-block-code"><code>SELECT TOP (1000) [Id]
      ,[messageId]
      ,[deviceId]
      ,[temperature]
      ,[humidity]
      ,[pressure]
      ,[pointInfo]
      ,[IoTHub]
      ,[EventEnqueuedUtcTime]
      ,[EventProcessedUtcTime]
      ,[PartitionId]
  FROM [dbo].[StreamData] order by [EventEnqueuedUtcTime] desc</code></pre>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="286" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/SQL-Server-Output-Data.jpg" alt="" class="wp-image-13486" srcset="/wp-content/uploads/2018/12/SQL-Server-Output-Data.jpg 651w, /wp-content/uploads/2018/12/SQL-Server-Output-Data-300x132.jpg 300w, /wp-content/uploads/2018/12/SQL-Server-Output-Data-400x176.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>SQL Server Output Data<br></figcaption></figure></div>



<h3 class="wp-block-heading">Checking Azure Function Output&nbsp;</h3>



<p>To check the Azure Function Output, we can go back to our Azure Function and click on the Function and use the <strong>Monitor </strong>option.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="1024" height="254" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Function-Output-Data-1024x254.jpg" alt="" class="wp-image-13487" srcset="/wp-content/uploads/2018/12/Azure-Function-Output-Data-1024x254.jpg 1024w, /wp-content/uploads/2018/12/Azure-Function-Output-Data-300x74.jpg 300w, /wp-content/uploads/2018/12/Azure-Function-Output-Data-768x190.jpg 768w, /wp-content/uploads/2018/12/Azure-Function-Output-Data-400x99.jpg 400w, /wp-content/uploads/2018/12/Azure-Function-Output-Data.jpg 1574w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Azure Function Output Data</figcaption></figure></div>



<p>Please be noted that you can always check your Azure Stream Analytics job Activity Log if you found something is not working.&nbsp;</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>In this article, we have learned how to,</p>



<ol class="wp-block-list"><li>work with an Azure Stream Analytics job</li><li>create an Azure Function App</li><li>create Azure Function App solution in Visual Studio</li><li>write an HttpTrigger&nbsp;function and publish the same to the Azure Function App</li><li>set up the Azure Function App as an output job topology of Azure Stream Analytics job</li><li>Use the created package in another solution</li></ol>



<p>In our next article, we will see how you can send this Azure Function Output data to an Azure SignalR service and then get the same data in an Angular Application. I can&#8217;t wait to write my next article.&nbsp;</p>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. I will come back with another post on the same topic very soon.&nbsp;Did I miss anything that you may think which is needed? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



<p>You can always see my IoT articles <a href="https://sibeeshpassion.com/category/iot/">here</a>.&nbsp;</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
