Create an Azure Blob Storage Account and Upload a File
An experienced technologist runs through the basics of using Azure Blog storage, including how to upload, modify, and delete files within Azure.
Join the DZone community and get the full member experience.Join For Free
Storage accounts are one of the fundamental pieces of cloud technology. They contain all of our Azure Storage data objects: blobs, files, queues, tables, and disks. Microsoft offers several options to store data on the cloud. Storage can be used for two purposes:
- One is to actually store files, just as we do on a hard disk.
- The other is to use it as the backend of a Virtual Machine. Many services within Azure need a storage account, sometimes for logging and sometimes as a fundamental piece of the technology. By default, Virtual Machines run on a managed storage account, which is an abstraction on top of a storage account. We cannot use it to create a Virtual Machine on top of an unmanaged account.
In this article, we will look at how to create an Azure blob storage account and upload a file on the blob.
There are various options available in the Azure Storage Account for storing user data.
The word blob is an acronym, which stands for a binary large object. Blobs typically include large files that are unstructured, such as images, video, music files, backup files, etc.
Blob storage can be divided into two access tiers;
- Hot access tier: Data which is accessed frequently will fall under this tier. In addition, hot storage tiers are highly available compared to the cold access tier; 99.9% as opposed to the 99% of the cold storage tier.
- Cold access tier: This tier is where we store data that is not accessed very often. In addition, the cold access tier is cheaper than the hot access tier and, as such, you can store more data at a lower cost.
Note: You can switch between access tiers at any point if you wish to do so.
With the help of Azure Files, we can set up highly available network file shares that can be accessed by using the standard Server Message Block (SMB) protocol. That means that multiple VMs can share the same files with both read and write access. We can also read the files using the REST interface or the storage client libraries.
There are multiple common scenarios where Azure File storage is very useful:
- Store configuration files on a file share that can be accessed from multiple VMs.
- We can keep resource logs, metrics, and crash dumps on a file share that can later be processed or used for analysis.
Queue Storage is somewhat like MSMQ. It allows us to decouple our components and have reliable asynchronous communication. In Azure Queue Storage, the number of queues is only limited by the capacity of the storage account. The Azure Queue service is used to store and retrieve messages. Queues and messages can be created programmatically or using the Storage Explorer tool.
Table storage is used to store semi-structured data in a key-value format in a NoSQL datastore. Azure table storage can store petabytes of data, can scale, and is inexpensive. Table storage can be accessed using REST and some of the OData protocols or using the Storage Explorer tool. Azure Table storage is now part of Azure Cosmos DB.
An Azure managed disk is a virtual hard disk (VHD). It is like a physical disk on an on-premises server, but virtual. Azure-managed disks are stored as page blobs, which are random IO storage objects in Azure. We call a managed disk 'managed' because it is an abstraction over page blobs, blob containers, and Azure storage accounts.
Azure offers two types of disk storage:
- Managed - A managed disk has some advantages over unmanaged disks in the sense that disks will be created and managed for us. This is an IaaS offering.
- Unmanaged - With unmanaged disks, we must manage them ourselves. This means, our virtual hard disks are stored in a storage account as page blobs.
Moreover, Azure offers two types of disks:
- Premium - Which means our data will be placed on solid-state disks.
- Standard - Our data will be placed on regular hard disk drives.
Creating Your First Azure Storage Account
There are multiple ways to create a storage account:
- Azure portal
- Azure PowerShell
- Azure CLI
- Azure Resource Manager (ARM) Template
In this article, we will use the first option, i.e. use the Azure portal. W will look into the other means in future articles.
- Log in to the Azure portal ➜ Search Storage Accounts ➜ then select Storage accounts from the search result
This will open a Storage account. Now we have to click on Add:
We have to fill in the mandatory details under the Basic section:
- Select the Subscription from the dropdown.
- Choose the Resource Group under this storage account you create.
- Provide the Storage account name, it should be unique across Azure and the length must be between 3-24 characters. Also, it may include only numbers and lowercase letters.
- Select the location of the Storage account or use the default location.
- Select a performance tier; the default tier is Standard.
- Set the Account field to Storage V2 (general-purpose v2).
- Select replication value, the default replication option is Read-access geo-redundant storage (RA-GRS). It will specify how the storage account will be replicated.
After entering all the values, the account will look like the following. If you want to keep the default values for the next section then click on 'Review + create', otherwise click on 'Next: Networking >'
Now we are in the networking section and here we can change the configurations related network connectivity and network routing.
In our case, we will keep the default settings.
For additional options, we will click on 'Next: Data protection >'.
In the Data protection section, we can define multiple configurations, like if want to turn on point-in-time restoration for containers. With the help of this configuration, we can restore one or more containers to an earlier state. We have to keep in mind one important point here: if we are going to enable this 'Point-in-time restore' configuration, then versioning, change feed, and blob soft delete must be enabled. The maximum restore point can be set to 6 days ago.
Next, let's configure Turn on soft delete for blobs. With this configuration, we can recover blobs that were previously marked to be deleted. Here we can define the number of days to keep deleted blobs.
Similarly, we have other configurations like:
- Turn on soft delete for containers.
- Turn on soft delete for file shares.
- Turn on versioning for blobs.
- Turn on blob change feed.
If you change these setting then it will look like the below image:
For our scenario, we will keep it set to default and will not change any configuration.
For additional options, we will click on 'Next: Advanced >'.
In the Advanced section, we can define the Security, Blob storage, Data Lake Storage Gen 2, Azure Files and Table, and Queues configuration.
Please check the configuration in the below image; for our scenario, I am keeping the default values.
The next option is Tags; we will bypass this section, because here you can just define the tags and their values. Now we will click on 'Review + create'.
Once we click on 'Review + Create', Azure will review your storage account settings and give the result of the review. In case all configurations are properly defined, we will get the message "Validation Passed." In addition, the 'Create' button will appear. Clicking on that button will create the Storage account. In case the validation fails, then it will give you the reasons why and how to fix that issue.
Here, we will get a link to download a template that we can use for automation.
It will take hardly a minute or two to complete the deployment. Once the deployment is completed, the below screen will appear. Then we can click on 'Go to resourc.'
This will open our newly created Storage account. Once it opens, then we have to create a container where we can upload the file. Click on 'Containers'; this will open the screen where we can create a new container.
Click on '+ Container' where we will upload the sample file.
Enter the name of the container and select the Public access level based on your need. For our scenario, we will keep this configuration as it is.
A container has been created successfully and now our final step is to upload a file. Click on upload, which will open a new panel where we will see a placeholder to select a file. In addition, we can see a checkbox that will be helpful to overwrite the already existing file.
In addition, we will have some advanced options to choose from:
Once we expand Advanced, it will give you the option to choose the blob type, block size, and Access tier. You can find the configuration I used below.
For our scenario, we will not touch anything in this section and keep this configuration as it is.
Now, click on the folder icon and it will open a pop-up to select the file from the folder. Select the file and click on open. Once the file is selected, click on 'Upload.'
Once the file is uploaded successfully, we will see the file available in the container along with other details.
Please verify the below screen to check the status of the uploaded file in the container.
Delete a Storage Account
Deleting a storage account deletes the entire account, including all data in the account and cannot be undone.
There are again multiple ways to delete the existing storage account:
- Azure portal.
- Azure PowerShell.
- Azure CLI.
- Azure Resource Manager (ARM) Template.
In this article, we will use the first option, i.e. using the Azure portal.
Log in to the Azure portal ➜ Search Storage Accounts ➜ then select the Storage accounts that you want to delete.
Once we open the storage account, we will have an option to delete it. Click on 'Delete.'
It will open the Delete storage account; here we have to type the name of the storage account to confirm. Then click on 'Delete.'
Caution: This action cannot be undone. This will permanently delete the storage account and its contents.
There are several advantages to using Azure storage irrespective of type. Azure storage is easily scalable, extremely flexible, and relatively low in cost depending on the options we choose.
Opinions expressed by DZone contributors are their own.