Automatic deletion of Blob through web job

prmanhas-MSFT 17,906 Reputation points Microsoft Employee
2025-01-24T08:53:35.4833333+00:00

We have an Event Based system in place where we have events getting triggered which in turn in handled by event hub and then it is moved to data table where after sometime the file get deleted. Now all this happens via job which run continuously and till event hub everything is working fine. We have a solution in place right now which is working but it is not working on all the storage accounts which is causing files to be still there in storage account. Is there any way storage tables can delete the data on their own after a span of 30 days or from code perspective do we need to make changes. Do let me know in case of any more information needed.

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,347 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Syed Aaqid Ali 5 Reputation points Microsoft Vendor
    2025-01-24T10:56:14.55+00:00

    Hello prmanhas-MSFT,

    Welcome to Microsoft Q&A Forum. Thanks for posting your query here!

    Yes, you can use Azure Blob Storage Lifecycle Management to automatically delete blobs (files) after a certain period of time. This can be done without any code changes.

    Here's how you can configure Lifecycle Management to delete blobs after 30 days:

    Open the Azure portal and navigate to your storage account.

    Click on "Lifecycle Management" under the "Blob service" section.

    Click on "Add rule" to create a new rule.

    Give the rule a name and select the "Delete" action.

    Set the "Days after last modification" value to 30.

    Optionally, you can also specify a prefix filter to only delete blobs with a certain prefix.

    Click on "Create" to save the rule.

    Once the rule is created, it will automatically delete blobs that are older than 30 days. This will work for all storage accounts that have Lifecycle Management enabled.

    However, lifecycle management policies are limited to the Blob service only therefore if you want to delete data from a storage table after a certain period of time, you can use the approach as you already follow that is Azure WebJobs.

    References: https://learn.microsoft.com/en-us/azure/storage/blobs/lifecycle-management-policy-configure?tabs=azure-portal

    If the answer helped or pointed you in the right direction please click Accept Answer which might be beneficial to other community members reading this thread. And, if you have any further queries do let us know. 

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.