Search code examples
powershellazure-api-managementazure-automation

Using Azure Automation - Graphical Runbook - to backup APIM to storage


I have a graphical runbook which backups up an instance of Azure API Management to Azure storage. I have used this technique in Powershell many times but thought i'd try it with a graphical runbook.

Here is my runbook: enter image description here

When I get the storage context from the New-AzureStorageContext and try to use it in the Backup-AzureRmApiManagement I get the following error: enter image description here

Here is how I hook the storage context from the previous activity to my backup activity:enter image description here

People suggest that the context gets serialized and that I should use an InlineScript but I can't get this to work.

Here is what I think is the serialized context: enter image description here

Would be great to get this to work.


Solution

  • Assuming that this is a Graphical (not Graphical PowerShell Workflow) runbook, there should be no serialization issues here.

    Most likely, the problem is caused by a mismatch of module versions in your Automation Account. The error message indicates that New-AzureStorageContext expects a parameter of type AzureStorageContext, and it receives a value of type AzureStorageContext. However, different module versions can refer to types defined in different assemblies, and the value cannot be converted to another type automatically. For example, New-AzureStorageContext from Azure.Storage (version A) may return an AzureStorageContext object incompatible with the type expected by Backup-AzureRmApiManagement from AzureRM.ApiManagement (version B). Unfortunately, the error message does not provide this information. In order to confirm that, you can run the following PowerShell runbook in the same Automation Account:

    (gcm New-AzureStorageContext).OutputType.Type.Assembly.FullName
    (gcm Backup-AzureRmApiManagement).Parameters.StorageContext.ParameterType.Assembly.FullName
    

    If they in fact point to different assemblies, you may need to import the matching versions of all Azure modules into your AutomationAccount. This script can help: https://github.com/azureautomation/runbooks/blob/master/Utility/ARM/Update-ModulesInAutomationToLatestVersion.ps1