Solve ‘yum: command not found’ in AWS Lambda Python 3.12 base image

πŸ“Œ The Issue

When I tried to install the Microsoft ODBC Driver (msodbcsql17) inside my custom image using the AWS Lambda Python 3.12 base image:

FROM public.ecr.aws/lambda/python:3.12

I used this command:

RUN yum install -y msodbcsql17

But it failed with this error:

/bin/sh: yum: command not found

❓ Why It Happens

Starting with Python 3.12, the Lambda base image now uses Amazon Linux 2023.
This version does not have yum anymore. It now uses microdnf, a lighter and faster package manager.

πŸ”— Official AWS Reference:

Starting with Python 3.12, the AWS base image uses Amazon Linux 2023 instead of Amazon Linux 2.
AWS Blog: AWS Lambda Adds Support for Python 3.12

πŸ› οΈ Solution: Use microdnf Instead of yum

To fix this, I replaced all yum commands with microdnf in my Dockerfile.

Here is the working Dockerfile for installing msodbcsql17:

FROM public.ecr.aws/lambda/python:3.12

# Set working directory
WORKDIR /opt/python/

# Install dependencies using microdnf
RUN microdnf update -y && \
    microdnf install -y \
        gcc gcc-c++ make unixODBC-devel unzip python3-devel wget && \
    wget -qO- https://packages.microsoft.com/keys/microsoft.asc | tee /etc/pki/rpm-gpg/MICROSOFT-GPG-KEY && \
    echo -e "[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod\nbaseurl=https://packages.microsoft.com/rhel/7/prod\nenabled=1\ngpgcheck=1\ngpgkey=file:///etc/pki/rpm-gpg/MICROSOFT-GPG-KEY" > /etc/yum.repos.d/msprod.repo && \
    ACCEPT_EULA=Y microdnf install -y msodbcsql17 && \
    microdnf clean all && \
    rm -rf /var/cache/yum /var/tmp/* /tmp/*

Key Points

  • microdnf is the new package manager in Amazon Linux 2023.
  • It works like yum for basic package installation.
  • This lets us install the msodbcsql17 driver needed to connect to Microsoft SQL Server from Lambda.

Final Result

After switching to microdnf, the image built successfully, and I was able to use pyodbc to connect to MS SQL Server inside Lambda using Python 3.12.

Extra Tip

If you’re packaging this as a Lambda Layer, copy only the needed .so files and drivers from /usr/lib64 and /opt/python to keep the layer size small.

πŸ™Œ Conclusion

If you’re using public.ecr.aws/lambda/python:3.12 and installing ODBC drivers or other system packages, make sure to use microdnf instead of yum.

πŸ“š Further Learning

If you want to explore more, here are some valuable reads:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.