1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Lambda関数でMySQLに接続する(セルフホスト)

Posted at

他社が公開しているパプリックなARNではなく、自前でレイヤーを用意するやり方。
https://qiita.com/drafts/2c74e5712d841a66a7ee

ファイル準備

任意のディレクトリに、以下2ファイルを配置

Dockerfile
FROM --platform=linux/x86_64 amazonlinux:2

ARG PYTHON_VERSION=3.11.1

RUN yum update -y && yum install -y tar gzip make gcc epel-release openssl11 openssl11-devel bzip2-devel libffi-devel \
  && curl https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz | tar xz \
  && export CFLAGS=$(pkg-config --cflags openssl11) && export LDFLAGS=$(pkg-config --libs openssl11) \
  && cd Python-${PYTHON_VERSION} && ./configure && make && make install \
  && cd - && rm -rf Python-${PYTHON_VERSION}

ADD entrypoint.sh /

RUN yum install -y zip \
  && mkdir /python \
  && chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
entrypoint.sh
#!/bin/bash -eu

SRC=/python
DIST=/dist/layer.zip

pip3 install -t ${SRC} $@
rm -f ${DIST}
zip -q -r ${DIST} ${SRC}

イメージのビルド

docker build --no-cache . -t lambda-layer

zip作成

docker run --rm -v ${pwd}:/dist lambda-layer:latest XXXX

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?