top of page
  • Writer's pictureAlibek Jakupov

Azure Functions on MacOS: a Step-by-Step guide



MacBooks have gained a strong following within the developer community, thanks to their impressive battery life, sleek design, user-friendly ergonomics, and robust processing power. However, developers often encounter obstacles when attempting to test Azure Functions locally on these devices, especially with the introduction of Apple Silicon chips (M1, M2, and M3). The core issue stems from certain libraries and tools that have yet to be optimized for compatibility with Apple's latest hardware.


In this tutorial, we aim to provide a clear and concise guide on how to configure your function app for local debugging. This will enable you to thoroughly test and refine your project prior to deploying it to a live server environment. We'll bypass the complexities and dive directly into the practical steps required to get your Azure Functions up and running on a MacBook with Apple Silicon. Up we go!



Important: As of the publication of this article, there may already be a solution in place, allowing all essential tools to operate natively on Apple's M-series chips without the need for emulation. Nonetheless, I remain optimistic that this content will prove to be useful or intriguing to someone. Should that be the case, my satisfaction would be complete.



 

My config

  • MacBook Air 13

  • Processor: M1

  • RAM: 16 Go

  • SSD: 256 Go

  • OS: Sonoma 14.1.2


Requirements


Azure Functions offers a serverless platform enabling you to reduce the amount of code you write, minimize your infrastructure management, and cut down on expenses. With the burden of server deployment and upkeep lifted, the cloud infrastructure ensures your applications remain operational with the necessary, current resources. Your primary concern becomes the crucial code you write, using the language that enhances your productivity, while Azure Functions takes care of everything else.



Prior to starting, ensure you have prepared the necessary elements:


  • An active Azure account with a subscription. You can sign up at no cost.

  • Visual Studio Code installed on your MacOS.

  • The Azurite V3 extension for emulating local storage. However it's possible to utilize a real Azure storage account.


To begin local development with Azure Functions, it's essential to have the Azure Functions Core Tools installed. However, if you're working on a Mac with the M1 chip, you'll encounter a compatibility issue as the Python worker for Azure Functions is not natively supported on the ARM architecture of the M1 chip. To overcome this challenge, you can employ a workaround by utilizing Rosetta 2, Apple's binary translation layer that enables applications compiled for x86_64 architecture to run on the ARM architecture. By setting up Rosetta 2, you can run the Python worker for Azure Functions on your M1 Mac, allowing you to proceed with your development workflow without any significant impediments.



Install Rosetta


Open Launchpad


Find your terminal (by default in the Utilities folder). Right-click and Get Info



Enable Rosetta by checking the corresponding box



If Rosetta is not installed, you're automatically asked to install it. Click Install, then enter your user name and password to allow installation to proceed. If you click Not Now, you will be asked again the next time you open an app that needs Rosetta.


Next time you open your Terminal you will there's zsh at the top of the window. This means you running the emulator now.


Install the tools


Now you can install the homebrew on your rosetta:

arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"


Don't forget to run the last two commands to add Homebrew to your PATH


Please note that it is essential to install Python on your Rosetta system independently. Failing to install the required version of Python may result in limited functionality, allowing you to run only basic applications. To ensure full compatibility with advanced applications, particularly those that depend on complex libraries like OpenAI, make certain to install the appropriate Python version. This will enable you to leverage the full capabilities of your sophisticated software without any limitations.


Compatible Python versions for Azure Functions are: 3.7, 3.8, 3.9, 3.10, 3.11, but we suggest using 3.10.


arch -x86_64 usr/local/bin/brew install python@3.10


As you have noticed the logic is quite straightforward, to install any package on Rosetta with brew run the following command

arch -x86_64 brew install <package>

Now you are ready to install the core tools




Run your first project


Open your VSCode. You first need to add code to the PATH environment variable


Now open the Palette (CMND + Shift + P) and add the Python extension (simply search Python)



And Azure Functions extension (search Azure function)




Now, choose the Azure icon in the Activity bar. Then in the Workspace (local) area, select the +button, choose Create Function in the dropdown. When prompted, choose Create new project.


Choose the directory location for your project workspace and choose Select. You should either create a new folder or choose an empty folder for the project workspace. Don't choose a project folder that is already part of a workspace.



Provide the following information at the prompts:




Visual Studio Code integrates with Azure Functions Core tools to let you run this project on your local development computer before you publish to Azure.

To start the function locally, press F5 or the Run and Debug icon in the left-hand side Activity bar. The Terminal panel displays the Output from Core Tools. Your app starts in the Terminal panel. You can see the URL endpoint of your HTTP-triggered function running locally.




Now, to ensure, we have the fully working emulator environment, go to requirements.txt, and add openai.


Rerun the function project.


If everything is alright, congratulations, you can now start developing.


May the force be with you!

119 views0 comments
bottom of page