├── .github └── FUNDING.yml ├── .gitignore ├── Dockerfile.mariadb ├── Dockerfile.mongodb ├── Dockerfile.mysql ├── Dockerfile.postgresql ├── Makefile └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [megastep] 2 | 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.zip 2 | 3 | -------------------------------------------------------------------------------- /Dockerfile.mariadb: -------------------------------------------------------------------------------- 1 | FROM amazonlinux:2 2 | 3 | WORKDIR /root 4 | 5 | RUN yum -y update && yum install -y tar gzip which zip mariadb binutils 6 | RUN mkdir -p /opt/bin /opt/lib 7 | 8 | RUN cp /usr/bin/mysql* /usr/bin/aria_* /usr/bin/msql2mysql /usr/bin/my_print_defaults /opt/bin/ 9 | RUN cp /usr/lib64/libncurses.so.6 /usr/lib64/libtinfo.so.6 /opt/lib/ 10 | RUN cd /opt; strip bin/* lib/*; zip -9r /root/mariadb-layer.zip bin lib 11 | -------------------------------------------------------------------------------- /Dockerfile.mongodb: -------------------------------------------------------------------------------- 1 | FROM amazonlinux:2 2 | 3 | WORKDIR /root 4 | 5 | ARG VERSION=100.4.0 6 | 7 | RUN yum -y update && yum install -y binutils gzip ncurses-devel tar wget zip 8 | 9 | RUN wget -q https://fastdl.mongodb.org/tools/db/mongodb-database-tools-amazon2-x86_64-${VERSION}.tgz 10 | RUN tar xzf mongodb-database-tools-amazon2-x86_64-${VERSION}.tgz 11 | 12 | RUN mkdir -p /opt/lib 13 | RUN cp -rp mongodb-database-tools-amazon2-x86_64-${VERSION}/bin /opt/ 14 | RUN cp /usr/lib64/libncurses.so.6 /usr/lib64/libtinfo.so.6 /opt/lib/ 15 | RUN cd /opt; strip bin/* lib/*; rm lib/*.a; zip -9r /root/mongodb-tools-${VERSION}-layer.zip bin lib 16 | -------------------------------------------------------------------------------- /Dockerfile.mysql: -------------------------------------------------------------------------------- 1 | FROM amazonlinux:2 2 | 3 | WORKDIR /root 4 | 5 | ARG VERSION=8.0.33 6 | 7 | RUN yum -y update && yum install -y cmake3 make gcc-c++ ncurses-devel openssl11 openssl11-devel python-devel wget tar gzip which zip 8 | 9 | RUN wget -q https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-${VERSION}.tar.gz 10 | 11 | RUN tar xzf mysql-${VERSION}.tar.gz 12 | RUN cd mysql-${VERSION}; mkdir build; cd build; cmake3 .. -DCMAKE_INSTALL_PREFIX=/opt -DWITHOUT_SERVER=ON -DDOWNLOAD_BOOST=ON -DWITH_BOOST=/root/boost && make install 13 | 14 | RUN cp /usr/lib64/libncurses.so.6 /usr/lib64/libtinfo.so.6 /usr/lib64/libssl.so.1.1 /usr/lib64/libcrypto.so.1.1 /opt/lib/ 15 | RUN cd /opt; strip bin/* lib/*; rm lib/*.a; zip -9r /root/mysql-${VERSION}-layer.zip bin lib share 16 | -------------------------------------------------------------------------------- /Dockerfile.postgresql: -------------------------------------------------------------------------------- 1 | FROM amazonlinux:2 2 | 3 | WORKDIR /root 4 | 5 | ARG VERSION=15.3 6 | 7 | RUN yum -y update && yum install -y make gcc-c++ ncurses-devel openssl-devel python-devel wget tar gzip which zip 8 | 9 | RUN wget -q https://ftp.postgresql.org/pub/source/v${VERSION}/postgresql-${VERSION}.tar.gz 10 | 11 | RUN tar xzf postgresql-${VERSION}.tar.gz 12 | RUN cd postgresql-${VERSION}; ./configure --without-readline --prefix=/opt; make \ 13 | && make -C src/bin install \ 14 | && make -C src/include install \ 15 | && make -C src/interfaces install 16 | 17 | RUN cp /usr/lib64/libncurses.so.6 /usr/lib64/libtinfo.so.6 /opt/lib/ 18 | RUN cd /opt; strip bin/* lib/*; rm lib/*.a; zip -9r /root/postgresql-${VERSION}-layer.zip bin lib share 19 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | MYSQL_VERSION = 8.0.33 2 | POSTGRESQL_VERSION = 15.3 3 | MONGODB_VERSION = 100.4.0 4 | 5 | all: mysql-$(MYSQL_VERSION)-layer.zip mariadb-layer.zip postgresql-$(POSTGRESQL_VERSION)-layer.zip mongodb-tools-$(MONGODB_VERSION)-layer.zip 6 | 7 | mysql: mysql-$(MYSQL_VERSION)-layer.zip 8 | mariadb: mariadb-layer.zip 9 | postgresql: postgresql-$(POSTGRESQL_VERSION)-layer.zip 10 | mongodb: mongodb-tools-$(MONGODB_VERSION)-layer.zip 11 | 12 | mysql-$(MYSQL_VERSION)-layer.zip: 13 | docker build -f Dockerfile.mysql . -t mysql-layer --build-arg VERSION=$(MYSQL_VERSION) 14 | container_id=$$(docker container create mysql-layer) && \ 15 | docker container cp $$container_id:/root/mysql-$(MYSQL_VERSION)-layer.zip . && \ 16 | docker container rm $$container_id 17 | 18 | mariadb-layer.zip: 19 | docker build -f Dockerfile.mariadb . -t mariadb-layer 20 | container_id=$$(docker container create mariadb-layer) && \ 21 | docker container cp $$container_id:/root/mariadb-layer.zip . && \ 22 | docker container rm $$container_id 23 | 24 | postgresql-$(POSTGRESQL_VERSION)-layer.zip: 25 | docker build -f Dockerfile.postgresql . -t postgresql-layer --build-arg VERSION=$(POSTGRESQL_VERSION) 26 | container_id=$$(docker container create postgresql-layer) && \ 27 | docker container cp $$container_id:/root/postgresql-$(POSTGRESQL_VERSION)-layer.zip . && \ 28 | docker container rm $$container_id 29 | 30 | mongodb-tools-$(MONGODB_VERSION)-layer.zip: 31 | docker build -f Dockerfile.mongodb . -t mongodb-layer --build-arg VERSION=$(MONGODB_VERSION) 32 | container_id=$$(docker container create mongodb-layer) && \ 33 | docker container cp $$container_id:/root/mongodb-tools-$(MONGODB_VERSION)-layer.zip . && \ 34 | docker container rm $$container_id 35 | 36 | clean: 37 | rm -f *.zip 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AWS Lambda Layers for MySQL, MariaDB, PostgreSQL and MongoDB Tools commands 2 | 3 | These layers add the `mysql`, `psql`, `mongodump`, `mongorestore` client commands in the form of a layer to be used with [AWS Lambda](https://aws.amazon.com/lambda/). 4 | 5 | This is useful for Lambda functions that need to run MySQL, PostgreSQL or MongoDB commands to quickly import data to a RDS server, for example. It can be easier than using the MySQL API in the language of your choice. Particularly useful in coordination with a [Bash lambda](https://github.com/gkrizek/bash-lambda-layer) layer. 6 | 7 | The layers (in the form of zip files) are built in Docker using the official AmazonLinux image, to match the typicial Lambda runtime environment. 8 | 9 | - The MySQL layer is built from the official source (v8.0.32) 10 | - The MariaDB layer is built from the binary files in the current `mariadb` AmazonLinux package. 11 | - The PostgreSQL layer is built from the official source (v9.2.24) 12 | - The MongoDB Tools layer is built from the official source (v100.4.0) 13 | 14 | ## Download 15 | 16 | Pre-built zip archives that can be uploaded to your AWS account are available on the [releases](https://github.com/megastep/mysql-lambda/releases) page. 17 | 18 | ## Building the layers 19 | 20 | If you have a working Docker setup, you just need to enter `make` to build both the MySQL and MariaDB layers. Alternatively: 21 | 22 | - `make mysql` builds the MySQL variant from source. 23 | - `make mariadb` builds the MariaDB variant from the pre-built packages. 24 | - `make postgresql` builds the PostgreSQL variant from source. 25 | - `make mongodb` builds the MongoDB variant from source. 26 | 27 | Note that the MySQL 8.0, PostgreSQL and MongoDB variants take considerably longer to build from source. 28 | 29 | ### Author 30 | 31 | [Stephane Peter](https://stephanepeter.com/) ([@megastep](https://github.com/megastep)) - [Sponsor me!](https://github.com/sponsors/megastep) 32 | --------------------------------------------------------------------------------