<?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 Job &#8211; Sibeesh Passion</title>
	<atom:link href="https://sibeeshpassion.com/tag/azure-job/feed/" rel="self" type="application/rss+xml" />
	<link>https://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 Job &#8211; Sibeesh Passion</title>
	<link>https://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://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>
	</channel>
</rss>
