<?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 Blob &#8211; Sibeesh Passion</title>
	<atom:link href="https://www.sibeeshpassion.com/tag/azure-blob/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Wed, 24 Jul 2019 15:24:53 +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 Blob &#8211; Sibeesh Passion</title>
	<link>https://www.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Azure Function Job to Delete Azure Blobs from Blob Containers</title>
		<link>https://www.sibeeshpassion.com/azure-function-job-to-delete-azure-blobs-from-blob-containers/</link>
					<comments>https://www.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://www.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://www.sibeeshpassion.com/timertrigger-azure-function-to-upload-to-azure-blob-daily/</link>
					<comments>https://www.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 fetchpriority="high" 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://www.sibeeshpassion.com/timertrigger-azure-function-to-upload-to-azure-blob-daily/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
