現在の実装では、Cloudflare Workers (workers/src/function.prod.ts) が以下の2つのエンドポイントでUpstash Redisに直接アクセスしています:
GET /page/{id}- 個別ページのOGP取得GET /user/{handle}- ユーザーのページID一覧取得(redis.scan()を使用)
利用が増加し、Upstash Redisの無料利用枠では収まらなくなってきました。
I want to use the trustmark package with AWS Lambda. However, I need the CPU version, not the CUDA version.
Succeeded pattern is below.
$ cp cpu_ubuntu.Dockerfile Dockerfile
$ docker build -t trustmark_lambda_sample .
....
=> [stage-1 8/8] COPY lambda/ /function/lambda/ 0.1s
=> exporting to image 27.2s| name | 形式 | 色深度 | サイズ | 色数 | 色サイズ比 | 最大サイズ比 | |
|---|---|---|---|---|---|---|---|
| Bitmap(RGB) | Bitmap | RGB | 5669654 | 16777216 | 2.9591 | 100.0% | |
| PNG(RGB) | PNG | RGB | 699634 | 16777216 | 23.9800 | 12.3% | |
| WebP(RGB) | WebP | RGB | 355712 | 16777216 | 47.1652 | 6.3% | |
| JPG(RGB) | JPG | RGB | 170070 | 16777216 | 98.6489 | 3.0% | |
| Bitmap(グレースケール) | Bitmap | グレースケール | 1892934 | 256 | 0.0001 | 33.4% | |
| PNG(グレースケール) | PNG | グレースケール | 295188 | 256 | 0.0009 | 5.2% | |
| WebP(グレースケール) | WebP | グレースケール | 204898 | 256 | 0.0012 | 3.6% | |
| JPG(グレースケール) | JPG | グレースケール | 134912 | 256 | 0.0019 | 2.4% | |
| BMP(モノクロ) | BMP | モノクロ | 238782 | 2 | 0.0000 | 4.2% |
| $ magick identify -verbose sample.webp | |
| Image: | |
| Filename: sample.webp | |
| Permissions: rw-rw-rw- | |
| Format: WEBP (WebP Image Format) | |
| Mime type: image/webp | |
| Class: DirectClass | |
| Geometry: 1600x1920+0+0 | |
| Units: Undefined | |
| Colorspace: sRGB |
| # AWS Lambda 関数の公式コンテナイメージ https://gallery.ecr.aws/lambda/python で | |
| # uv https://docs.astral.sh/uv/ を使って python パッケージ管理と実行を可能にする最小限の例 | |
| FROM public.ecr.aws/lambda/python:3.12 | |
| # uv を公式イメージからCOPYする方法でインストールする | |
| # https://docs.astral.sh/uv/guides/integration/docker/#installing-uv | |
| COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv | |
| ENV PATH="/app/.venv/bin:$PATH" | |
| # AWS Lambda は書込可能なディレクトリが `/tmp` 配下だけなので uv の cache も同ディレクトリ配下を使うように変更する |
| FROM amazon/aws-lambda-python:3.9 | |
| COPY . ${LAMBDA_TASK_ROOT} | |
| ENV PYTHONUTF8=1 | |
| ENV APP_NAME=${APP_NAME:-SOME_APP_NAME} | |
| # Install AWS Cli | |
| RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \ | |
| && unzip awscliv2.zip \ | |
| && ./aws/install \ |
| import logging | |
| from logging import StreamHandler | |
| logger = logging.getLogger("sample") | |
| _fmtr = logging.Formatter("%(asctime)s %(levelname)s [%(name)s] %(message)s") | |
| _handler = StreamHandler() | |
| _handler.setFormatter(_fmtr) | |
| logger.addHandler(_handler) | |
| logger.setLevel("DEBUG") |