我正在尝试在本地测试 lambda 函数,该函数是从 aws 的公共 docker 映像创建的,但是我想从我的 github 安装我自己的 python 库,根据文档AWS sam Build我必须添加一个变量像这样在 Dockerfile 中获取:
FROM public.ecr.aws/lambda/python:3.8
COPY lambda_preprocessor.py requirements.txt ./
RUN yum install -y git
RUN python3.8 -m pip install -r requirements.txt -t .
ARG GITHUB_TOKEN
RUN python3.8 -m pip install git+https://${GITHUB_TOKEN}@github.com/repository/library.git -t .
Run Code Online (Sandbox Code Playgroud)
为了传递 GITHUB_TOKEN,我可以创建一个包含 docker 环境变量的 .json 文件。
{
"LambdaPreprocessor": {
"GITHUB_TOKEN": "TOKEN_VALUE"
}
}
Run Code Online (Sandbox Code Playgroud)
只需在 sam 构建中传递文件地址:sam build --use-container --container-env-var-file env.json或者直接使用以下命令传递不带 .json 的值:sam build --use-container …