Today I was designing a solution where I had to store files for a certain amount of time in Azure Blob Storage.
I first thought I had to design and build this feature myself but I discovered that this feature is available out of the box through ‘Lifecycle Management’.
Therefore:
- Open your Storage account on the Azure portal.
- Go to Lifecycle Management in the Data Management section.
- Click on Add a rule.
- The Add a rule wizard is loaded. Specify a rule name and select the applicable blob types. Click on Next.
- Specify the applicable conditions and the corresponding action. Click on Add to create the Rule.
- That’s it!
- Be aware that it can take up to 48 hours before a new or updated rule
Remark: It is also possible to directly use a lifecycle management policy file. This is a collection of rules in a JSON document.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"rules": [ | |
{ | |
"name": "rule1", | |
"enabled": true, | |
"type": "Lifecycle", | |
"definition": {...} | |
}, | |
{ | |
"name": "rule2", | |
"type": "Lifecycle", | |
"definition": {...} | |
} | |
] | |
} |
More information
Optimize costs by automatically managing the data lifecycle - Azure Storage | Microsoft Learn