7

Create an Azure Blob Storage Account and Upload a File

 2 years ago
source link: https://dzone.com/articles/azure-create-azure-blob-storage-account-and-upload
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Introduction

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.

Blob Storage

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 that 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.

File Storage

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:

  1. Store configuration files on a file share that can be accessed from multiple VMs.
  2. We can keep resource logs, metrics, and crash dumps on a file share that can later be processed or used for analysis.

Queue Storage

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

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:

  1. 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.
  2. 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:

  1. Premium- Which means our data will be placed on solid-state disks.
  2. 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:

  1. Azure portal
  2. Azure PowerShell
  3. Azure CLI
  4. 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.

1.Search.png

This will open a Storage account. Now we have to click on Add:

2.Add_StorageAccount.PNGWe have to fill in the mandatory details under the Basic section:

  1. Select the Subscription from the dropdown.
  2. Choose the Resource Group under this storage account you create.
  3. 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.
  4. Select the location of the Storage account or use the default location.
  5. Select a performance tier; the default tier is Standard.
  6. Set the Account field to Storage V2 (general-purpose v2).
  7. 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 >'

3.SA_Basic.PNGNow we are in the networking section and here we can change the configurations related to network connectivity and network routing.

In our case, we will keep the default settings.

For additional options, we will click on 'Next: Data protection >'.

4.SA_Networking.PNGIn 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:

  1. Turn on soft delete for containers.
  2. Turn on soft delete for file shares.
  3. Turn on versioning for blobs.
  4. Turn on blob change feed.

If you change these settings then it will look like the below image:

5.2.SA_DataProtection.PNGFor our scenario, we will keep it set to default and will not change any configuration. For additional options, we will click on 'Next: Advanced >'.

5.1.SA_DataProtection.PNGIn 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'.

6.SA_Advanced.pngOnce 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.

7.SA_Review_Create.pngIt 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 resource.'

8.Deployment.PNGThis 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.

9.FirstStorageAccount.PNGClick on '+ Container' where we will upload the sample file.

10.Container..PNGEnter 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.

11.Container_Config..PNGA 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:

12.Upload_blob..PNGOnce 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.

13.Upload_blob.Config.PNGNow, 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.'

14.Upload_blob.File.PNGOnce 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.

16.Upload_blob.Success.PNGDelete 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:

  1. Azure portal.
  2. Azure PowerShell.
  3. Azure CLI.
  4. 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.'

17.Delete_Storage_account.PNGIt will open the Delete storage account; here we have to type the name of the storage account to confirm. Then click on 'Delete.'

17.Delete_Storage_account-1.PNGCaution: This action cannot be undone. This will permanently delete the storage account and its contents.

Conclusion

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK