Skip to content

Instantly share code, notes, and snippets.

@lucafrost
Last active July 21, 2022 13:59
Show Gist options
  • Save lucafrost/a5989e207027748c85f3968e0c92554c to your computer and use it in GitHub Desktop.
Save lucafrost/a5989e207027748c85f3968e0c92554c to your computer and use it in GitHub Desktop.
M1 / Apple Silicon Workaround for Azure Functions

Workaround on Apple Silicon

1. Installing Rosetta

  1. Run the following command in terminal: softwareupdate --install-rosetta --agree-to-license
    • This will install Apple's Rosetta which emulates x64_86 architecture.
  2. Navigate to ~/Applications/ and duplicate 'Terminal'
    • You may wish to rename the duplicate "Rosetta Terminal"
  3. Secondary-click your new terminal, navigate to 'Get Info', and check the 'Open using Rosetta' box.

You have now created a second terminal application that will always run as x64_86. Test this by entering arch, it should show as i386 as opposed to arm64. You can always enter python -c "import platform;print(platform.machine())" to test that the Python interpreter is running on Rosetta.

The two terminals share the same preferences (i.e. theme), so using a new icon for the Rosetta terminal is advised. The process for replacing an application icon is well documented online. A high-fidelity image of the Apple Rosetta logo can be found here

2. Installing Dependencies

  1. Install the intel arch for brew: arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
    • Good practice to run echo 'eval "$(/usr/local/bin/brew shellenv)"' >> /Users/USERNAME/.zprofile and eval "$(/usr/local/bin/brew shellenv)" after brew install
  2. Create a new Conda env (named rosetta): CONDA_SUBDIR=osx-64 conda create -n rosetta python=3.9

⚠️ Python 3.9.X is the latest version supported by Azure CLI & Funcs

  1. Activate new Conda env: conda activate rosetta
  2. Install Azure Functions Core Tools by running arch -x86_64 brew tap azure/functions then arch -x86_64 brew install azure-functions-core-tools@4
  3. Install Azure CLI: arch -x86_64 brew update && arch -x86_64 brew install azure-cli
  4. Run az login to authenticate in browser.
    • You should see something like the following...
     [
       {
         "cloudName": "AzureCloud",
         "homeTenantId": "a000000-b000-c000-d000-e00000000000",
         "id": "a000000-b000-c000-d000-e00000000000",
         "isDefault": true,
         "managedByTenants": [],
         "name": "Pay-As-You-Go",
         "state": "Enabled",
         "tenantId": "a000000-b000-c000-d000-e00000000000",
         "user": {
           "name": "first.last@example.com",
           "type": "user"
         }
       }
     ]
    
  5. Navigate to the project directory & run pip install -r requirements.txt

3. Testing that all is A-OK

  1. Start the app: Azure already knows that the directory contains a function app. You do not need to initiate a new function app, simply run func start host
    • Your endpoint should be localhost:7071...
    • There is no authentication 👋 Goodbye Ocp-Apim-Subscription-Key
    • Should the above perform as expected, you're off... Happy Coding 🤖🚀
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment