How to Import Python Packages in Azure Automation

I encountered some difficulties with package management when executing Python files in Azure Automation, so I decided to summarize my findings.

Overall

I wanted to run Python files on a regular basis and discovered that Azure Automation could be a viable solution. However, I encountered the following error which prevented execution: No module named ‘****’ This error indicates that the module does not exist, but in Azure Automation, Python packages cannot be installed via pip, and it is necessary to import them separately into the Automation account. The publicly available information on this method was somewhat unclear, so I have outlined the steps. While it is possible to manually import packages, I believe that the following method is smoother for importing dependencies all at once.

Manage Python 3 packages in Azure Automation

Note: The content of this information (including attached documents, links, etc.) is based on the time of creation and may be subject to change without notice.

Step

  1. Enable Managed Identity Enable the managed identity for the Automation account. This time, we used the system-assigned identity.

managedid

  1. Grant Automation Co-Administrator Permission Grant Automation co-administrator permissions to this ID.

iam

  1. Download the Python File Download the Python file from the link provided in the public information. This time, we are referencing the link for using the system-assigned identity.

Import a package with dependencies

  1. Create a Runbook Create a Runbook by importing from Azure Automation’s Runbook.

import

  1. Execute the Runbook Specify parameters when executing this Runbook.
1
2
3
4
5
-s <subscription id>
-g <resource group>
-a <automation account name>>
-m <module>
-v <version>

For example:

1
2
3
4
5
-s xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx
-g contosogroup
-a contosoaccount
-m pytz
-v 1.0.0

execute

If the execution is successful, the dependent packages will be imported together.

Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy