I need mysqldump
(or mariadb-dump
) inside my Lambda function.
I chose I want to go the Docker way and used the public.ecr.aws/lambda/nodejs:20
base image.
To add MySQL/MariaDB I added the following to my Dockerfile
RUN dnf update -y && dnf install -y mariadb105-server
This works but bloats the image size to ~800MB.
Is there a better/easier way to only add mysqldump
and the necessary dependencies?
I looked at the other services AWS offers but none really fit the bill ...
Dockerfile I'm testing with
FROM public.ecr.aws/lambda/nodejs:20
# Installing mysqldump and cleaning dnf cache
RUN dnf update -y && \
dnf -y install mysql-utilities && \
dnf clean all && \
# dnf autoremove -y && \ # => not working b/c this is only microdnf which doesn't have autoremove
rm -rf /var/cache/{dnf,yumdb,metadata}
Build command I use
docker build . --platform linux/amd64 -t mysqldump-node20
I'm not sure it's the easiest but I think the lightweight solution is to bundle the mysqldump binary in your zip code source. Here were my steps:
sudo wget https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm
sudo dnf install mysql80-community-release-el9-1.noarch.rpm -y
sudo dnf install mysql-community-server -y
sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023
then rerun the last step.usr/bin/mysqldump
to your machine to zip with your code.Then I just needed to make sure my code referenced it in the correct directory it ended up in based on folder structure of the zip.