Installing libxml2 (xmllint) in node10.x runtime

0

I have a lambda that uses node8.x we were recently notified that the lambda 8.x run-time is reaching EOL and we should upgrade to node 10.x. That's all well and good, but I'm running into a problem. My lambda uses a binary (xmllint) to validate XML, but the libxml2 (and shell command xmllint) are not available in the environment.

I assume I should create a layer for this, but I'm not sure how to get the dynamic linked libraries to work. Any suggestions?

I've created a docker file to compile libxml2 and zip the files into a layer

FROM amazon/lambda-build-node10.x

RUN yum -y upgrade && \
    yum -y install gcc \
                   python-devel \
                   libxml2-devel \
                   libxslt-devel \
                   wget \
                   which \
                   tar \
                   xz \
                   gzip \
                   make \
                   zip


RUN wget http://xmlsoft.org/sources/libxml2-2.9.10.tar.gz
RUN gunzip -c libxml2-2.9.10.tar.gz | tar xvf -

RUN mkdir -p /package && \
    mkdir -p /host

RUN cd libxml2-2.9.10 && \
    ./configure --prefix=/package \
                --disable-static \
                --with-python=/usr/bin/python3 && \
    make && \
    make install

After I create the layer and attach it to my lambda - When I invoke the lambda and shell out to xmllint I facing this error. Any suggestions or ideas?

xmllint: error while loading shared libraries: liblzma.so.5: cannot open shared object file: No such file or directory
asked 5 years ago866 views
1 Answer
0

I've finally figured out the problem. I'm going to post here in case this is helpful to others. It was helpful to see the shared object files using the ldd command. After seeing this, I figured I cold resolve this by install xz from source and include that as part of the layer.

Here are the steps I ran.

  1. Build the docker image - I gave it a tag of amzlinux2
$ docker build -t amzlinux2 .
  1. Next, run the container
$ docker run -it --rm -v "$PWD":/host amzlinux2 bash
  1. In the container we need to zip up the files so we can upload them as a layer
$ cd /opt && zip --symlinks -r /host/libxml2.zip ./*
  1. At this point you'll have a libxml2.zip file on your host machine. You can upload this as a layer and add it to your function.

ldd

$ ldd /opt/bin/xmllint    
    
linux-vdso.so.1 (0x00007ffcd9de0000)\    
libxml2.so.2 => /opt/lib/libxml2.so.2 (0x00007ffb7f28f000)\    
libdl.so.2 => /lib64/libdl.so.2 (0x00007ffb7f08b000)\    
libz.so.1 => /lib64/libz.so.1 (0x00007ffb7ee75000)\    
liblzma.so.5 => not found\    
libm.so.6 => /lib64/libm.so.6 (0x00007ffb7eb2a000)\    
libc.so.6 => /lib64/libc.so.6 (0x00007ffb7e774000)\    
/lib64/ld-linux-x86-64.so.2 (0x00007ffb7f5e1000)\    
liblzma.so.5 => not found\    

Dockerfile

FROM amazon/lambda-build-node10.x

RUN yum -y upgrade && \
    yum -y install gcc \
                   python-devel \
                   libxml2-devel \
                   libxslt-devel \
                   wget \
                   which \
                   tar \
                   gzip \
                   make \
                   zip


RUN wget http://xmlsoft.org/sources/libxml2-2.9.10.tar.gz
RUN gunzip -c libxml2-2.9.10.tar.gz | tar xvf -

RUN mkdir -p /host

RUN wget https://tukaani.org/xz/xz-5.2.4.tar.gz
RUN tar xvfz xz-5.2.4.tar.gz

RUN cd xz-5.2.4 && \
		./configure --prefix=/opt && \
    make && \
    make install

RUN cd libxml2-2.9.10 && \
    ./configure --prefix=/opt \
                --disable-static \
                --with-python=/usr/bin/python3 && \
    make && \
    make install
answered 5 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions