Hosting a Static Website with Azure Blob Storage

45 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Azure Storage Blobs are a great tool for storing all kinds of data, but they can also be used to serve that data anywhere in the world. As such, Blobs can be used to host and serve a simple, static website.

In this lab, you will have the opportunity to work with Azure Storage Blobs by using them to host a static website. You will create and configure the necessary storage account, and you will upload static files to Blob storage. When you finish, you will be able to view the static website in your browser.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a storage account to host the static website.
  1. Click + Add to create a new resource.
  2. Search for and select Storage Account.
  3. For Resource Group, select the existing resource group if it is not already selected.
  4. Enter a Storage account name that begins with staticsite. You may need to add some characters at the end of the name to make it unique.
  5. Click Review + Create, then Create.
Configure the storage account for static site hosting.
  1. Wait for your storage account to finish being created. When viewing the resource group, you can click Refresh. When your storage account appears in the list, it has been created.
  2. Click on your storage account, then click Static Website on the left side of the storage account pane.
  3. Click Enabled to enable static website hosting for the storage account.
  4. For Index document name, enter index.html.
  5. Click Save.
Upload the static site files.
  1. Log in to Azure Cloud Shell at https://shell.azure.com.
  2. Select Bash, then advanced settings. Select use existing for all three fields, and enter cloudshell for the container.
  3. Get the key for the storage account. Note that you can find the resource group name in the Azure portal. The storage account name is the name of the storage account you created earlier.
    export AZURE_STORAGE_ACCOUNT="&ltstorage account name>"
    export RESOURCE_GROUP="&ltresource group name>"
    az storage account keys list 
    --account-name $AZURE_STORAGE_ACCOUNT 
    --resource-group $RESOURCE_GROUP 
    --output table
  4. Set an environment variable containing the storage account key.
    export AZURE_STORAGE_KEY="&ltkey>"
  5. Clone the lab resources repository from GitHub and switch to the static site directory.
    git clone https://github.com/linuxacademy/content-azurestoragedd-lab-resources.git
    cd content-azurestoragedd-lab-resources/satt-static-site/
  6. Upload the static site files as blobs within the $web container.
    az storage blob upload-batch -d "$web" -s .
  7. In Azure portal, navigate back to the static site storage account and select Static Website again. This page contains a URL under Primary Endpoint. Copy this URL and access it in a new tab.

You should see the website for Store All The Things!

Additional Resources

Your physical storage company, Store All The Things!, can store literally anything. They want to be able to advertise this fact to prospective customers, and a company website is a major part of that process.

The decision has been made to host a simple, static website using Azure Storage Blobs. The static files can be found in GitHub at https://github.com/linuxacademy/content-azurestoragedd-lab-resources under the satt-static-site directory.

Create and configure an Azure storage account to serve a static website, then upload the static website files to Blob Storage. When you are finished, you should be able to view the static website in your browser at the storage container's primary endpoint.

You can upload the files using Azure Cloud Shell. You can access the cloud shell at https://shell.azure.com. When accessing the shell, select "advanced settings," and use the existing storage account that resides in the West US location.

If you get stuck, feel free to check out the solution video, or the detailed instructions under each objective. Good luck!

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?