Update nodejs 16 to nodejs 20 for AWS lambda

0

I have limited knowledge of docker and aws I am trying to update the nodejs from 16 to 20 but i am getting this error "error Package: 2:nodejs-20.12.2-1nodesource.x86_64 (nodesource-nodejs) Requires: libc.so.6(GLIBC_2.28)(64bit)"

My dockerfile :

FROM amazon/aws-cli:2.8.3 RUN yum update -y
&& curl --silent --location https://rpm.nodesource.com/setup_20.x | bash -
&& yum install -y nodejs which zip
&& yum clean all
&& rm -rf /var/cache/yum

The reason for this error is aws-cli is using amazonlinux:2 which only has glibs version 2.26

This same dockerfile works for nodejs 16 version

I tried various things like using amzonlinus:2023 as installer dockerfile:

FROM amazon/aws-cli:2.15.42 FROM public.ecr.aws/amazonlinux/amazonlinux:2023 as installer

RUN yum update -y
&& curl --silent --location https://rpm.nodesource.com/setup_20.x | bash -
&& yum install -y nodejs which zip
&& yum clean all
&& rm -rf /var/cache/yum

but this also fails stating Errors during downloading metadata for repository 'amazonlinux': Curl error (6): Couldn't resolve host name for https://cdn.amazonlinux.com/al2023/core/mirrors/2023.4.20240429/x86_64/mirror.list [getaddrinfo() thread failed to start]

I tried using amazon docker image too but that also didn't work

FROM public.ecr.aws/lambda/nodejs:20.2024.05.01.10

can someone please help me and share a dockerfile that works in installing nodejs 20

asked 5 months ago743 views
1 Answer
4

Hlo,

t seems like you're facing compatibility issues with the GLIBC version when trying to install Node.js 20 on Amazon Linux 2, which comes with GLIBC version 2.26. Node.js 20 requires a higher version of GLIBC (specifically GLIBC 2.28).

# Use an image with the necessary GLIBC version
FROM public.ecr.aws/amazonlinux/amazonlinux:2 as builder

# Install Node.js 20
RUN curl --silent --location https://rpm.nodesource.com/setup_20.x | bash -
RUN yum install -y nodejs

# Final image
FROM amazon/aws-cli:2.8.3

# Copy Node.js from the builder image
COPY --from=builder /usr/bin/node /usr/bin/node
COPY --from=builder /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6
COPY --from=builder /usr/lib64/libgcc_s.so.1 /usr/lib64/libgcc_s.so.1

# Other dependencies and cleanup
RUN yum install -y which zip \
    && yum clean all \
    && rm -rf /var/cache/yum

# Confirm Node.js and npm versions
RUN node -v && npm -v

This Docker file starts by using the Amazon Linux 2 base image. Then it installs Node.js 20 from the Node Source repository. The crucial part is copying necessary Node.js files and dependencies from the builder image to the final image. This ensures that the GLIBC version compatibility issue is resolved.

Please note that this Docker file assumes you have access to the AWS CLI image and necessary permissions to pull it.

EXPERT
answered 5 months ago
  • Hi Thanniru,

    I tried the approach you mentioned but with the dockerfile you shared the issue is you are still using amazonlinux:2 as builder hence when in the next step it tries to install node 20 it gets the same error of glibc version incompatibility

    now in place of amazonlinux:2 if i use amazonlinux:2023 as builder than my build pipeline is failing again with the error: Errors during downloading metadata for repository 'amazonlinux': Curl error (6): Couldn't resolve host name for https://cdn.amazonlinux.com/al2023/core/mirrors/2023.4.20240429/x86_64/mirror.list [getaddrinfo() thread failed to start]

    so this is kind of going in loop. i tried using the image provided by amazon which is FROM public.ecr.aws/lambda/nodejs:20

    but in this case my when my pipeline try to push my image it seems to be giving 503 service unavailable error

  • any further leads would help

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