Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serverless NodeJS / Native node_modules

I'm having an issue getting a node module to load in AWS Lambda using the Serverless Framework. One of my node packages uses native libraries so I used an EC2 to create the node_module folders and then copied them to my Serverless project. Everything works if I manually zip the project and upload to AWS Lambda but if I use serverless deploy without an artifact specified, I get an error about the module (specifically: ELF file's phentsize not the expected size regarding a .node file)

I've tried adding excludeDevDependencies: false which makes the deployment larger but still gives me the error. Currently, it only works if I zip the contents of the project folder and specify that file as the artifact to upload. Is there a different way to get a node module with native bindings to deploy with Serverless?

UPDATE: After turning off the exclusion of dev dependencies, packaging using serverless package and examining the expanded zip file serverless creates, I discovered the file sizes of the .o and .a files are different in the packaged version as compared to the original. Is this normal?

enter image description here

like image 813
arvinkx Avatar asked Oct 30 '22 02:10

arvinkx


1 Answers

I ran into this problem and did some digging. It turns out that v1.21.0 of serverless broke packaging of binaries.

https://forum.serverless.com/t/serverless-1-21-0-breaks-sharp-library/2606

https://github.com/serverless/serverless/issues/4182

The recommended fix is to upgrade to v1.21.1.

like image 146
Josh Vickery Avatar answered Nov 15 '22 05:11

Josh Vickery