This guide explains how to securely configure your Azure ML workspace connection using config.json and test that it works properly.
/Users/mcdaniel/Desktop/gh/fswl/azureml-example/config.json
Pros:
- Automatically detected by
Workspace.from_config() - Project-specific configuration
- Already in
.gitignore(secure)
Cons:
- Need separate config for each project
~/.azure_ai/config.json
Pros:
- Shared across all Azure ML projects
- Standard Azure ML location
- Outside project directory
Cons:
- Global configuration (may not work if you have multiple workspaces)
config.jsonis in.gitignore✅- Won't be committed to version control ✅
chmod 600 config.json # Read/write for owner onlyFor production/CI environments, use environment variables instead:
from azure_ai.core import Workspace
# Using environment variables
ws = Workspace(
subscription_id=os.environ['AZUREML_SUBSCRIPTION_ID'],
resource_group=os.environ['AZUREML_RESOURCE_GROUP'],
workspace_name=os.environ['AZUREML_WORKSPACE_NAME']
)For automated deployments, use service principal authentication:
from azure_ai.core.authentication import ServicePrincipalAuthentication
svc_pr = ServicePrincipalAuthentication(
tenant_id=os.environ['AZURE_TENANT_ID'],
service_principal_id=os.environ['AZURE_CLIENT_ID'],
service_principal_password=os.environ['AZURE_CLIENT_SECRET']
)
ws = Workspace(
subscription_id=os.environ['AZUREML_SUBSCRIPTION_ID'],
resource_group=os.environ['AZUREML_RESOURCE_GROUP'],
workspace_name=os.environ['AZUREML_WORKSPACE_NAME'],
auth=svc_pr
)- Go to Azure ML Studio: https://ml.azure.com
- Select your workspace from the workspace dropdown
- Click the download icon (⬇️) next to your workspace name in the top navigation
- Save the file as
config.json
The downloaded file should look like this:
{
"subscription_id": "your-subscription-id",
"resource_group": "your-resource-group-name",
"workspace_name": "your-workspace-name"
}# Run the setup script
python setup_config.py
# Run the test
python azure_ai/tests/test_azureml.py# From project root
python azure_ai/tests/test_azureml.pyThe test script will check:
-
✅ Azure ML SDK Installation
- Core modules import correctly
- Training estimators available
- Pipeline components accessible
-
✅ Configuration File Detection
- Searches multiple locations for config.json
- Validates file structure
- Reports found location
-
✅ Workspace Connection
- Connects to your Azure ML workspace
- Displays workspace information
- Verifies authentication
Successful Test:
Testing Azure ML Installation
========================================
✅ Azure ML Core version: 1.48.0
✅ Azure ML Core classes imported successfully
✅ Azure ML Training estimators imported successfully
✅ Azure ML Pipeline components imported successfully
⚠️ AutoML components skipped (has dependency conflicts)
✅ Found config.json at: ./config.json
🔄 Attempting to connect to Azure ML workspace...
✅ Successfully connected to workspace: my-workspace
Subscription: 12345678-1234-1234-1234-123456789012
Resource Group: my-resource-group
Location: eastus
========================================
✅ Azure ML installation and configuration are working!
Next steps:
1. Create your first experiment
2. Upload data to your workspace
3. Train your first model
❌ config.json not found
Solution: Download config.json from Azure ML Studio and place it in project root
❌ Workspace connection error: AuthenticationException
Solutions:
- Check if you're logged into Azure CLI:
az login - Verify config.json has correct subscription ID
- Ensure you have access to the workspace
❌ Workspace connection error: Forbidden
Solutions:
- Check your Azure ML workspace permissions
- Ensure you're using the correct subscription
- Contact your Azure administrator
❌ Workspace connection error: ConnectionError
Solutions:
- Check internet connectivity
- Verify corporate firewall settings
- Try using VPN if on restricted network
./config.json # Local development workspace
# Use environment variables
ws = Workspace.from_config(path="./config-staging.json")# Use service principal authentication
ws = Workspace(
subscription_id=os.environ['AZUREML_SUBSCRIPTION_ID'],
resource_group=os.environ['AZUREML_RESOURCE_GROUP'],
workspace_name=os.environ['AZUREML_WORKSPACE_NAME'],
auth=svc_pr
)- Never commit config.json to version control
- Use different workspaces for dev/staging/prod
- Use service principal auth for automated deployments
- Set restrictive file permissions on config files
- Regularly rotate service principal secrets
- Monitor workspace access and usage
- Use Azure Key Vault for production secrets
After successful configuration:
- Create your first experiment
- Upload training data
- Set up compute targets
- Train your first model
- Deploy models to endpoints