theam / aws-lambda-haskell-runtime

⚡Haskell runtime for AWS Lambda
https://theam.github.io/aws-lambda-haskell-runtime/
Other
269 stars 48 forks source link

Unable to find Libpcre in runtime environment #36

Closed JonathanLorimer closed 5 years ago

JonathanLorimer commented 5 years ago

I get this error when trying to run my Lambda:

/var/task/bootstrap: error while loading shared libraries: libpcre.so.3: cannot open shared object file: No such file or directory

I am not sure what is requiring this dependency when everything is compiled down. Everything builds find in the stack docker image

My haskell dependencies look like this:

dependencies:
  - aeson
  - aws-lambda-haskell-runtime >= 2.0.0
  - base >= 4.7 && < 5
  - bson
  - containers
  - http-conduit
  - monad-logger
  - mtl
  - mongoDB
  - persistent
  - persistent-mysql
  - persistent-template
  - text
  - time

I don't think any of this is too out of the normal. I was having some issues with OpenSSL and persistent-mysql on my machine that required me to install with these flags enabled in my stack.yaml:

extra-include-dirs: [/usr/local/opt/openssl/include]
extra-lib-dirs: [/usr/local/opt/openssl/lib]

but everything seemed to compile using stack build --docker.

Any ideas what is causing this? I imagine it is something to do with not having access to the Libpcre library in the runtime, but I don't know what is causing my project to depend on that library.

If you need more information let me know. Thanks.

NickSeagull commented 5 years ago

Thanks for reporting :)

Would it be possible for you to provide a small repo to reproduce this so we can work on this issue?

JonathanLorimer commented 5 years ago

https://github.com/JonathanLorimer/aws-lambda-haskell-error

I was able to reproduce the issue in this simple app that just ports data from an SQL db to a Mongo db.

My suspicion is that one of my haskell dependencies, when compiled down, requires libpcre.so.3, and that the layer you provided doesn't include it. My thoughts on solving in the short term was to add my own layer that includes this debian package on top of yours.

If it's helpful I can include the entire error message from AWS.

NickSeagull commented 5 years ago

After taking a closer look, I suspect the same thing as you. In fact, in the serverless-haskell plugin, you can see here that libpcre appears as one of the libraries that should be copied. (Which is what serverless-haskell is doing currently)

As a quick workaround, you could add the copying of these files to your Makefile. I hope that the addition of this runtime to serverless-haskell gets merged soon, so one can use Serverless framework for an easier experience :)

Tell me if this works for you, if not I'll try to come up with a better solution.

JonathanLorimer commented 5 years ago

This worked! A co-worker and I tried this last night but we messed up the path, had to use LD_LIBRARY_PATH to specify where the additional libs were. Turns out the dependency that was requiring these libraries was the Haskell mysql driver (which makes sense).

NickSeagull commented 5 years ago

Sounds good! I've created #37 to document this case, could you please check if it is a correct solution for this please? :)