Jerry
Jerry

Reputation: 1782

Programmatically enable static website on azure storage

As Static website feature on Azure storage accounts is no longer in preview mode, is there a way to set this option programmatically (via Powershell Az commands / Azure CLI)?

Currently the only way I can see is to do it manually in UI:

enter image description here

Upvotes: 5

Views: 2510

Answers (2)

Anass Kartit
Anass Kartit

Reputation: 2088

According to the documentation:

https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website

you can use CLI

az storage blob service-properties update --account-name <ACCOUNT_NAME> --static-website --404-document <ERROR_DOCUMENT_NAME> --index-document <INDEX_DOCUMENT_NAME>

Upvotes: 10

Erndob
Erndob

Reputation: 2612

You can use blob storage rest api.The endpoint for setting blob service properties. You can change static website properties from 2018-03-28 api version.

PUT https://<account-name>.blob.core.windows.net/?restype=service&comp=properties

Body:

<?xml version="1.0" encoding="utf-8"?>  
<StorageServiceProperties>  
    <StaticWebsite>
        <Enabled>true|false</Enabled>
        <IndexDocument>default-name-of-index-page-under-each-directory</IndexDocument>
        <ErrorDocument404Path>absolute-path-of-the-custom-404-page</ErrorDocument404Path>
    </StaticWebsite>
</StorageServiceProperties>  

Refer to docs on how to authorize yourself.

https://learn.microsoft.com/en-us/rest/api/storageservices/set-blob-service-properties

Powershell abstraction exists.

Enable-AzStorageStaticWebsite -IndexDocument $indexdoc -ErrorDocument404Path $errordoc https://learn.microsoft.com/en-us/powershell/module/az.storage/enable-azstoragestaticwebsite?view=azps-1.3.0

Upvotes: 2

Related Questions