Programmatically enable static website on azure storage
Asked Answered
S

2

5

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

Sunroom answered 22/2, 2019 at 9:53 Comment(0)
D
2

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

Dredger answered 22/2, 2019 at 10:14 Comment(1)
Enable-AzStorageStaticWebsite is exactly what I was after. Thanks.Sunroom
C
10

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>
Cellulosic answered 22/2, 2019 at 10:45 Comment(0)
D
2

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

Dredger answered 22/2, 2019 at 10:14 Comment(1)
Enable-AzStorageStaticWebsite is exactly what I was after. Thanks.Sunroom

© 2022 - 2024 — McMap. All rights reserved.