AzureBatch ImageReference class 下的自定义图像无法正常工作

Custom Image under AzureBatch ImageReference class not working

我有一个自定义 VHD 文件。我可以通过门户用我的自定义图像创建池。但我想尝试使用 .Net SDK。但它抛出错误 "Operation returned an invalid status code 'Forbidden"。

我指的是这个 link Azure Batch

我能够使用相同的代码从 MarketPlace 图像创建池 下面是我的代码

ImageReference imageReference = new ImageReference("/subscriptions/XXXXXXXXXXXXXXX/resourceGroups/RG-OneGolden/providers/Microsoft.Compute/images/OMGoldenImage");


                VirtualMachineConfiguration virtualMachineConfiguration =
                new VirtualMachineConfiguration(
                    imageReference: imageReference,
                    nodeAgentSkuId: "batch.node.windows amd64");

                try
                {
                    CloudPool pool = batchClient.PoolOperations.CreatePool(
                        poolId: PoolId,
                        targetDedicatedComputeNodes: PoolNodeCount,
                        virtualMachineSize: PoolVMSize,
                        virtualMachineConfiguration: virtualMachineConfiguration);

                    pool.Commit();
                }
                catch (BatchException be)
                {
                    // Accept the specific error code PoolExists as that is expected if the pool already exists
                    if (be.RequestInformation?.BatchError?.Code == BatchErrorCodeStrings.PoolExists)
                    {
                        Console.WriteLine("The pool {0} already existed when we tried to create it", PoolId);
                    }
                    else
                    {
                        throw; // Any other exception is unexpected
                    }
                }

您需要确保满足 prerequisites Azure Batch 中自定义图像的要求:

  1. ARM Image 与 Batch 帐户处于相同的订阅和区域。
  2. 您正在使用 Azure Active Directory 对 Batch 服务进行身份验证。