Introduction

This small and quick lab showcases some of what you can do with azcopy (make sure you have the far superior v10 or newer), as well as the simplicity of hosting static website content in an Azure storage account.

I wrote it for a partner following a query, and then promptly hid it away from the categories. (This is why it is rather no frills compared to much of the content on this site.)

If you have static website content and negligible site traffic then this is a quick and inexpensive way of hosting it on Azure.

Required

The following steps have been checked on the Windows Subsystem for Linux with both az and azcopy installed.

Initial Steps

Login to Azure, create the resource group and add the preview storage commands to the CLI.


az login
az account show
az group create --name staticwebsite --location westeurope
az extension add --name storage-preview

Unique names

The storage account names need to be globally unique. Set the values of the $src and $dst variables to something that should be unique.


subId=$(az account show --output tsv --query id)
prefix=$(whoami | tr '[:upper:]' '[:lower:]')
suffix=$(/usr/bin/md5sum <<< $subId | cut -c1-10)
src=${prefix}src${suffix}
dst=${prefix}dst${suffix}

West Europe storage account

Create the v2 storage account, store the key


az storage account create --name $src --resource-group staticwebsite --location westeurope --kind StorageV2 --sku Standard_LRS
srckey=$(az storage account keys list --account-name $src --resource-group staticwebsite --query "[1].value" --output tsv)

North Europe storage account

Repeat for North Europe.


az storage account create --name $dst --resource-group staticwebsite --location northeurope --kind StorageV2 --sku Standard_LRS
dstkey=$(az storage account keys list --account-name $dst --resource-group staticwebsite --query "[1].value" --output tsv)

Copy a sample HTML webpage locally


git clone https://github.com/richeney/azure101-webapp-html
rm -fR azure101-webapp-html/.git
cd azure101-webapp-html

Create the static website in the source storage account


az storage container create --name \$web --account-name $src --account-key $srckey
azcopy --source ~/azure101-webapp-html/ --destination https://$src.blob.core.windows.net/\$web/ --dest-key $srckey --recursive
az storage blob service-properties update --account-name $src --static-website --404-document 404.html --index-document index.html
az storage account show --name $src --output tsv --query primaryEndpoints.web

The last line shows the static web page endpoint. Copy into your browser to check that the page is working.

Copy the files recursively from one storage account to another


az storage container create --name \$web --account-name $dst --account-key $dstkey
azcopy --source https://$src.blob.core.windows.net/\$web/ --destination https://$dst.blob.core.windows.net/\$web/ --source-key $srckey --dest-key $dstkey --recursive
az storage blob service-properties update --account-name $dst --static-website --404-document 404.html --index-document index.html
az storage account show --name $dst --output tsv --query primaryEndpoints.web

Check that the destination storage account’s static website is up.

Done!

Leave a comment