zappa / Zappa

Serverless Python
https://zappa.ws/zappa
MIT License
3.22k stars 361 forks source link

Support for Lambda on Arm CPUs #1051

Open nickovs opened 2 years ago

nickovs commented 2 years ago

Context

Amazon recently announced that they are now offering Lambda running on their custom Graviton2 CPUs. These are built around the Arm CPU architecture instead of Intel, apparently offering up to 19 percent better performance at 20 percent lower cost.

Zappa does not currently have a way to indicate which CPU architecture it should use for deployment. Furthermore, for Python packages that have binary components Zappa currently always fetches the wheel files for the x86_64 architecture.

It would be valuable if Zappa supported deployment on the Arm platform by means of a configuration setting.

Expected Behavior

n/a

Actual Behavior

n/a

Possible Fix

The code that implements core.create_lambda_function() calls the CreateFunction AWS API endpoint to create the Lambda function. Amazon has updated the API to add a new Architectures argument that can be set to either x86_64 or arm64 (with the former as the default). A new architecture configuration setting should set this argument.

The regular expressions that find the suitable wheel files and check for cached wheels will need to be updated to find the wheels for the correct architecture.

NinitoAS commented 2 years ago

Any PRs for this issue?

turingbeing commented 2 years ago

Any PRs for this issue?

I will work on this issue

dickermoshe commented 2 years ago

Zappa will upload to ARM if your system is running ARM. You could use mlupin/docker-lambda:python3.9-build-arm and use QEMU to emulate it on x86. Other than that there no other solution.

nickovs commented 2 years ago

@dickermoshe I'm not sure that you are correct when you say: "Zappa will upload to ARM if your system is running ARM." Firstly, Zappa tries to upload whole .whl wheel files and it explicitly looks for x86_64 wheels, so if use a package that has a binary component and you you have something different on your local machine it will go and fetch the Intel versions. Secondly, the existing code never sets the architecture type for the requested Lambda instance and so this will always default to an Intel instance. As a result even when I deploy from ARM machines (either Raspberry Pi with 64bit OS or M1 Mac) it runs Zappa on an Intel Lambda instance.

As for needing emulation, I don't think that is the case either. Zappa requires either pure Python modules or pre-built wheels; if there are existing ARM architecture wheel files then nothing needs to get built.

dickermoshe commented 2 years ago

My mistake. You're 100% right. It always looks for x86. I'll shut up now 😳

van4oza commented 11 months ago

Hi! Any news? I'm so waiting for this feature!)

sebatyler commented 6 months ago

Many people are waiting for this feature. I hope it will be released soon!

mkotsollaris commented 2 months ago

hey folks, any updates on this?

ebar0n commented 1 month ago

hey folks, any updates on this?

nickovs commented 1 month ago

It looks like a PR (#1123) was created three years ago, but lay idle for too long and got auto-closed.

@javulticat @lmuther8 Any chance you could merge one of the several PRs that fix this? Back in 2021, not all binary wheels had ARM support and AWS didn't offer ARM for Lambda in all regions. Now Arm64 is everywhere, both inside AWS and across the wider Linux, Mac and Windows communities. AWS's ARM offerings for Lambda have about 50% better price/performance ratio than x86, so merging support for architecture control would save people a lot of money!

sknutsonsf commented 1 month ago

Please merge and finish the ARM support - the PR looks like it will work.

I'm having to dig out my 4 year old ancient PC to update our API app.