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?
"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",
"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?
Hello. Which version of rhino3dm are you using? How are you referencing it in your project?
My project is consuming the Rhino3dm (version 7.14.0) NuGet package.
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
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:
“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”,
“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:
Just to clarify, you are setting the environment to be x86_64? From what I can tell, AWS Lambda supports
Yes sir, I am definitely setting the environment to x86_64.
Ok, we might need to try this out ourselves to see if we can duplicate the issue.
Any assistance would be appreciated. If it would help I can probably bundle up my project folder and send it to you.
Hello Mike. This would help us get going. Please send it to luis at mcneel dot com.
Just sent you the example project!
Hey Luis, just wondering if you have had an opportunity to look over the example project that I sent you.
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.
Hoping to be able to use File3dm in AWS Lambda soon. Bumping the thread for attention. Has anyone had any experience or luck doing this?
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
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.