Azure CLI出现SubscriptionNotFound错误:订阅ID正确且拥有Owner权限
解决Azure CLI创建存储账户时的SubscriptionNotFound错误
问题场景
已确认订阅ID正确、拥有Owner角色,订阅处于Enabled状态且设为默认订阅,能正常创建资源组,但执行az storage account create命令时触发以下错误:
(SubscriptionNotFound) Subscription MY_SUBSCRIPTION_ID_HERE was not found. Code: SubscriptionNotFound Message: Subscription MY_SUBSCRIPTION_ID_HERE was not found.
本地PowerShell/Bash及Azure云Shell均出现此问题。
解决步骤
检查并注册Microsoft.Storage资源提供商
新创建的订阅可能未自动注册存储服务对应的资源提供商,执行以下命令完成注册:az provider register --namespace Microsoft.Storage等待注册完成(可能需要数分钟),通过以下命令确认注册状态为
Registered:az provider show --namespace Microsoft.Storage --query registrationState显式指定订阅ID执行存储账户创建命令
跳过上下文依赖,在创建命令中直接指定订阅ID:az storage account create --name MY_STORAGE_NAME --location eastus --resource-group MY_GROUP_RESOURCE_NAME --sku Standard_LRS --subscription MY_SUBSCRIPTION_ID_HERE清除Azure CLI缓存并重新登录
缓存异常可能导致上下文识别错误,执行以下操作重置:az cache purge --all az login az account set --subscription MY_SUBSCRIPTION_ID_HERE验证订阅状态与配额
确认订阅无隐藏限制,检查状态及存储配额:# 确认订阅状态 az subscription show --subscription MY_SUBSCRIPTION_ID_HERE --query 'state' # 检查存储账户名称合规性 az storage account check-name --name MY_STORAGE_NAME # 查看存储服务配额 az quota show --subscription MY_SUBSCRIPTION_ID_HERE --scope "subscriptions/MY_SUBSCRIPTION_ID_HERE/providers/Microsoft.Storage"
内容的提问来源于stack exchange,提问作者ChristianOConnor
相关产品推荐
相关产品推荐

