'Why is my AWS Lambda crashing when running in ARM64 architecture?
I'll summarize my issue.
I have a solution containing multiple .NET lambdas (3.1) which I deploy using serverless, all of which work just fine in the old architecture (x86_64) but when I changed the architecture setting to arm64 (and saw that it updated the actual lambda in console) whenever I actually run the lambda it crashes.
Unable to load assembly 'Lambda.Api'.: LambdaException
19 Oct 2021 09:22:15,116 [WARN] ([email protected]:331 errno: None) run_dotnet(dotnet_path, &args) failed
Unknown application error occurred
I have three questions regarding this.
- How do I get more information from the logs regarding the failure? I tried adding logs but nothing showed, this error happened too early and I need to find a way to debug the process locally, maybe to see which dependency I need to fix.
- Is this issue due to anything other than dependencies? What else could it be caused by?
- If this is caused by DLL dependencies, how do I find which one?
Solution 1:[1]
I'm not sure, but probably you have to pass arm64
parameter during the packaging
dotnet lambda package -farch arm64
Solution 2:[2]
I just has a very similar issue following the switch to arm64 from x86 for .NET6 lambda functions. The error when executing the function was:
Unhandled exception. System.BadImageFormatException: Could not load file or assembly 'Amazon.Lambda.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. An attempt was made to load a program with an incorrect format.
I am deploying the functions using serverless framework to reference zip files. The fix was to update the command that creates the zip files, however my first attempt did not work. The "runtime" (--runtime linux-arm64) parameter is not sufficient, despite being documented in the AWS GitHub pages.
It is necessary to add the "function-architecture" parameter as well (or instead?). My successful package command looks like this:
dotnet lambda package --package-type zip --output-package function.zip --configuration "Release" --function-architecture arm64 --runtime linux-arm64
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Ben Wesson |