Search code examples
azureenvironment-variablescloudazure-storage

is there a way to set env variables within azure storage account


I've enabled Static website within azure storage account, deployed to it a simple React webapp within $web container that has been created automatically just after enabling static website.

I am wondering is there a way to setup environment variables within azure storage account, and is there an alternative to do so, and how?


Solution

  • is there a way to set env variables within azure storage account?

    I agree with Not Found's comment. In Azure Storage static website hosting, there is no way to set environment variables as part of the static website feature itself.

    As for the approach, if you need to use environment variables, you can store them within a .env file or in a secure location, such as Github action secrets, build your project, and then deploy it to Azure Storage.

    For example, you can store the value of the environment variable REACT_APP_API_KEY as a GitHub Actions secret and reference it in your workflow file as follows, if your React app needs it:

    - name: Build and deploy React app
      env:
        REACT_APP_API_KEY: ${{ secrets.MY_SECRET_ENV_VAR }}
      run: |
        npm install @azure/storage-blob
        npm run build
        az storage blob upload-batch --destination '$web' --source build
    

    In the app service, certain settings are available to the deployment or runtime environment as environment variables, but in Azure storage, there is no way to set environment variables.