MicrosoftLearning / mslearn-knowledge-mining

Lab files for Azure AI Knowledge Mining modules
https://microsoftlearning.github.io/mslearn-knowledge-mining/
MIT License
81 stars 152 forks source link

Exercises/01-azure-search.html - Could not execute instructions via Visual Studio code but found workaround #31

Closed kgbarnes91 closed 5 months ago

kgbarnes91 commented 6 months ago

For context, I tried to do this with the following system: iMac 2020 on Sonoma 14.4.1

I made sure Azure CLI, Powershell, and the Python packages were installed, my Azure storage and AI search were all in the same Azure multi-services resource group, and I used the Storage data for configuration of authorization to my "UploadDocs.cmd" file

Upload Documents to Azure Storage

Per the exercise instructions, Step 5 states, after syncing one's Azure CLI to Visual Code, to run the following command to upload the soon-to-be used documents for the experiment in using Azure AI Search:

UploadDocs

I couldn't get that to execute in either my zsh shell or Powershell via Visual Code... I tried, "Invoke-Command [file-path\UploadDocs.cmd]", "Invoke-Item [file-path\UploadDocs.cmd]", ".\UploadDocs.cmd", or simply, "UploadDocs.cmd" and on zsh I tried, "sh UploadDocs.cmd", to no avail with all of the above.

My Workaround - Execute Azure CLI commands directly in the terminal/zsh

I probably tried some more, but I can't remember. I'm not sure if this is an error but the workaround that I ended up using was to copy/paste the 'call' instructions from the UploadDocs.cmd file and replace the fields: "!azure_storage_account!", "!subscription_id!", and "!azure_storage_key!"

with the corresponding authorization data for my storage account.

Thereafter, I executed the commands in my zsh terminal (with Azure CLI installed and logged into, of course) and when I checked my portal, I saw the container added with the first command executed and when uploading the data for the lab, I saw the batch being uploaded and confirmed as completed via the terminal shell itself. Hope it helps, and also would love to hear what the optimal solution was that was originally intended for the lab. I imagine same can be done similarly with Powershell for Windows users once Azure CLI is installed but considering I'm on a Mac, I switched back to use of zsh when executing the Azure CLI commands.

happychuks commented 5 months ago

My solution that worked: Convert the script to a Bash Shell Script:

#!/bin/bash

# Set values for your storage account
subscription_id="YOUR-SUBSCRIPTION-ID"
azure_storage_account="STORAGE-ACCOUNT-NAME"
azure_storage_key="STORAGE-KEY"

# Create container
echo "Creating container..."
az storage container create \
  --account-name "$azure_storage_account" \
  --subscription "$subscription_id" \
  --name margies \
  --public-access blob \
  --auth-mode key \
  --account-key "$azure_storage_key" \
  --output none

# Upload files
echo "Uploading files..."
az storage blob upload-batch \
  -d margies \
  -s data \
  --account-name "$azure_storage_account" \
  --auth-mode key \
  --account-key "$azure_storage_key" \
  --output none

THEN RUN FILE USING: bash UploadDocs.sh Let me know if it help