azureazure-backup-vaultazure-python-sdk

Creating Azure Recovery Service Vault - Python SDK - bad request


I am trying to create a Recovery Service Vault in Azure using Python SDK. Package version: azure-mgmt-recoveryservices==2.0.0

Code snippet:

client=RecoveryServicesClient(client_secret_credential, subscription_id)
client.vaults.begin_create_or_update(
    resource_group_name="my-custom-rg",
    vault_name="name_of_the_vault",
    vault={
        "location": "centralus", 
        "sku": {
            "name": "Standard",
        },
        "identity": {
            "type": "SystemAssigned",
        }
    }
)

I got the following error:

  File "/<my-computer-path>/azure/lib/python3.8/site-packages/azure/mgmt/recoveryservices/operations/_vaults_operations.py", line 293, in _create_or_update_initial
    raise HttpResponseError(response=response, error_format=ARMErrorFormat)
azure.core.exceptions.HttpResponseError: Operation returned an invalid status 'Bad Request'

What am I doing wrong? How could I do more "error investigation"?


Solution

  • Thank you Robert. Posting your suggestion as an answer to help other community members.

    This error azure.core.exceptions.HttpResponseError: Operation returned an invalid status 'Bad Request' is caused by missing backup_policy_resource properties.

    policy_resource = BaseBackupPolicyResource(properties=backup_policy)
    
    poller = client.backup_policies.create_or_update(
        vault_name="my-vault-name",
        resource_group_name="my-resource-group",
        backup_policy_name="my-daily-backup",
        parameters=policy_resource
    )
    

    You can refer to How to create disk Backup Policy using azure python SDK?