File too short on shared library libpcre2-8.so.0
Hi!
I am trying to run git with this layer in a SAM lambda build.
Template snippet:
LambdaFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: app.lambda_handler
Runtime: python3.7
Layers:
- arn:aws:lambda:eu-west-1:553035198032:layer:git:10
Code snippet:
subprocess.call(['git', 'init', '/tmp/Apps/CDN/'])
or
os.system('cd /tmp/Apps/CDN && git init')
All attempts fail with git: error while loading shared libraries: /opt/lib/libpcre2-8.so.0: file too short
I also tried using the second version of the layer (despite py3.7 not being listed for it) instead, but that also fail with the same error.
Any ideas how this can be solved?
Same issue here when running locally using sam-cli. Is this layer compatible with sam-cli?
@cvanes I don't think sam-cli knows how to deal with symlinks properly (unlike Lambda itself). There are a bunch of issues open about it on that repo I believe
@fongie were you getting this error in a production Lambda, or just running sam locally?
You can get it running on sam cli, but you'll need to unzip the layer zip manually yourself and change your Layers configuration unfortunately. You can see a similar example of this over here: https://github.com/lambci/yumda#full-example-with-aws-sam
There's a PR open at sam-cli to fix the symlink issue, but it doesn't look like it's had much love recently: https://github.com/awslabs/aws-sam-cli/pull/1482
Thanks! That explains it, and the example should get me started. I got the error running locally and the code never made it to production yet because of it. Is there reason to believe it would work if I pushed it to AWS?
Yep, absolutely – it's purely a bug in sam cli. If you use docker-lambda directly you should be able to get it to work locally (you'll just need to mount the layer directory manually)
Unrelated to sam-cli, this issue was resolved for me by ensuring git, if run within a child process within Lambda, is provided LD_LIBRARY_PATH (and also I believe PATH) env vars from the host Lambda process. Fwiw!