I have created a fairly simple AWS lambda function, written in C# and .NET 6.0, to read a 3dm file and return some simple information about the objects in the document (object name, layer name, bounding box). Currently I am reading the 3dm file into a byte array and then encoding that byte array into a string and passing the string into the lambda as input. Inside the lambda I decode the string back into a byte array and then call File3dm.FromByteArray. In the future the files will likely be uploaded to S3 and Iâll read them directly from that.
Iâm receiving the following error back from AWS and it seems to be struggling with a DLL dependency?
{
"errorType": "DllNotFoundException",
"errorMessage": "Unable to load shared library 'librhino3dm_native' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibrhino3dm_native: cannot open shared object file: No such file or directory",
"stackTrace": [
"at UnsafeNativeMethods.ONX_Model_FromByteArray(Int32 length, Byte[] buffer)",
"at Rhino.FileIO.File3dm.FromByteArray(Byte[] bytes)",
"at LambdaTestRhino3dm.Function.FunctionHandler(TestFile testFile) in C:\\svn\\3DStuff\\RenderService\\LambdaTestRhino3dm\\Function.cs:line 43",
"at lambda_method1(Closure , Stream , ILambdaContext , Stream )",
"at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.Invoke(Stream lambdaData, ILambdaContext lambdaContext, Stream outStream) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 145",
"at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass8_0.<GetHandlerWrapper>b__0(InvocationRequest invocation) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/HandlerWrapper.cs:line 56",
"at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs:line 176"
]
}
Any suggestions what I am doing wrong or if what Iâm trying to do is even possible?
I think we are building a specific version of rhino3dm that targets the .net version used in AWS Lambda. Iâm investigating this and will get back to you when I get further info.
The dotnet version we build for linux is targeting dotnet Core SDK 3.1.302. Is there a way you could use a dotnet core 3.1 environment and see if you still get issues?
Another issue might be the .net runtime. We arenât building for arm64. Is there a way to specify x86_64?
I am currently trying your suggestions. Iâm running into some trouble trying to invoke the lambda but at the moment Iâm not sure if it is something I am doing wrong or not. I will update you on my progress soon.
Ok so I was able to rebuild my lambda project to target dotnetcore 3.1 and publish it. I made sure that I was specifying x86 architecture when publishing. When I invoke my lambda it is still failing and returns the following:
{
âerrorTypeâ: âDllNotFoundExceptionâ,
âerrorMessageâ: âUnable to load shared library âlibrhino3dm_nativeâ or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibrhino3dm_native: cannot open shared object file: No such file or directoryâ,
âstackTraceâ: [
âat UnsafeNativeMethods.ON_Layer_New()â,
âat Rhino.DocObjects.LayerâŚctor()â,
âat MikeSample31Net.Function.FunctionHandler(String testFile) in C:\svn\3DStuff\LambdaTestRhino3dm\MikeSample31Net\Function.cs:line 17â,
âat lambda_method(Closure , Stream , Stream , LambdaContextInternal )â
]
}
The line in question is simply instantiating a local variable with a new Rhino.DocObjects.Layer object and it is the first time in my function that any reference is made to the Rhino3dm package.
The zip package that the publish creates looks like this:
I started to look at but was away last week. I hope to get a better look at this this week, but please bear with me, Iâve never used AWS Lambda before.
So Iâve started poking at aws lambda. I am finding some issues with a net6.0 x86_64 and net7 x86_64 (from docker image) lambdas trying to find the librhino3dm_native library. Will report back when I have more information.
So I did some git archeology and saw that 7.6 was the last build before we switched to building rhino3dm on CircleCI to GitHub Actions. We would build rhino3dm in a docker container that ran Amazon Linux. Using that same image, installing dotnet 7, and building the latest code resulted in initial tests of it working on aws lambda.
If anyone would like to try it, this artifact, which contains the Rhino3dm.dll and librhino3dm:native.so, will be around for the next 15 days. I would appreciate any feedback if you try it out.
Finally got back to this project. Using the artifacts that you shared, I was able to successfully run File3dm code in my Lambda!
To get this to work I did the following:
Removed Rhino3dm NuGet package
Added the Rhino3dm.dll in your zip to my project and set the properties of both to BuildType = âContentâ and Copy to Output Directory = âCopy Alwaysâ.
Added the librhino3dm_native.so in your zip to my project and set the properties of both to BuildType = âContentâ and Copy to Output Directory = âCopy Alwaysâ.
I added an assembly reference to the Rhino3dm.dll included
At this point I tried to build and publish my Lambda project but received an error which indicated a configuration issue with my project PublishReadyToRun setting.
I edited my project file to change the PublishReadyToRun setting from âtrueâ to âfalseâ
At this point I was able to publish successfully and my Lambda function works and was able to read an uploaded 3dm and return data that I extracted from it.