Using gnupg2-full in AWS Lambda base image for Python3.12

86 Views Asked by At

Apparently AWS switched their Python base images for AWS Lambda to Amazon Linux 2023. I have a Lambda function which uses gnupg and was working fine on older base images.

With the Python3.12 upgrade, I am hitting some issues. Apparently Amazon Linux 2023 just comes with gnupg2-minimal and the recommendation is to install gnupg2-full instead using this.

However, when I pull the docker images to my local machine and then run the container and SSH into it, the command dnf swap gnupg2-minimal gnupg2-full just gives me this:

bash-5.2# dnf swap gnupg2-minimal gnupg2-full
This is microdnf, which implements subset of `dnf'.
Usage:
  dnf [OPTION?] COMMAND

Commands:
  upgrade              Upgrade packages
  update               Compatibility alias for the "upgrade" command
  module reset         Reset a module stream
  distro-sync          Upgrade/downgrade packages to match versions in repositories
  dsync                Compatibility alias for the "distro-sync" command
  remove               Remove packages
  reinstall            Reinstall packages
  clean                Remove cached data
  repolist             List repositories
  module enable        Enable a module stream
  download             Download packages
  makecache            Generate the metadata cache
  module disable       Disable a module stream
  repoquery            Search for packages matching keyword
  install              Install packages

So I cannot even use swap with microdnf? What are my options here? Would really like to get a full version of gnupg2 installed ...

3

There are 3 best solutions below

0
On

After spending some time investigating, I decided to use an alternative base image with the runtime interface client.

This is the Dockerfile that I am using with AWS Lambda.

ARG FUNCTION_DIR="/opt/function"

FROM python:3.12-slim-bookworm

ARG FUNCTION_DIR

RUN apt-get update

RUN apt-get -y install gnupg2

RUN mkdir -p ${FUNCTION_DIR}

COPY src/requirements.txt ${FUNCTION_DIR}

COPY src/ ${FUNCTION_DIR}

WORKDIR ${FUNCTION_DIR}

RUN pip install --no-cache-dir -r requirements.txt

RUN pip install boto3 awslambdaric

ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]

CMD ["app.handler"]

0
On

I found this workaround:

RUN rpm -e gnupg2-minimal --nodeps && \
    dnf -y install gnupg2-full
0
On

I found I needed to download the package first..

RUN dnf -y download gnupg2-full && \
  rpm -e gnupg2-minimal --nodeps && \
  dnf -y install gnupg2-full && \
  rm -f gnupg2*.rpm