0

所以我使用 AWS SAM 来构建和部署一些功能到 AWS Lambda。由于我的连接速度很慢,上传功能很慢,所以我决定在其中创建一个带有需求的图层。所以下次我尝试部署功能时,我不必上传所有 50 mb 的需求,我可以使用已经上传的层。

问题是我找不到任何参数可以让我忽略需求文件并只部署源代码。

甚至可能吗?

4

2 回答 2

0

我希望我能正确理解你的问题,但如果你想部署一个没有任何依赖关系的 lambda,你可以尝试两件事:

  • sam build前不跑sam deploy
  • 有一个空的 requirements.txt 文件。然后sam build根本不包括该 lambda 函数的任何依赖项。

当然,在这里我假设该层已经存在于 AWS 中,并且不包含在同一个模板中。如果它们在同一个模板中定义,则必须将它们分成两个堆栈。一个带有可以部署一次的层,另一个带有引用该层的 lambda。

不幸sam build 的是,据我所知,没有标志可以忽略 requirements.txt,因为该命令的核心目的是构建依赖项。

于 2021-02-20T09:35:11.627 回答
0

For everyone using image container, this is the solution I have found. It drastically improve the workflow.

Dockerfile [it skip if requirments.txt is unchanged]

FROM public.ecr.aws/lambda/python:3.8 AS build

COPY requirements.txt ./
RUN python3.8 -m pip install -r requirements.txt -t .

COPY app.py ./
COPY model /opt/ml/model

CMD ["app.lambda_handler"]

What I have changed?

This was the default Dockerfile

FROM public.ecr.aws/lambda/python:3.8

COPY app.py requirements.txt ./
COPY model /opt/ml/model

RUN python3.8 -m pip install -r requirements.txt -t .

CMD ["app.lambda_handler"]

This solution is based on https://stackoverflow.com/a/34399661/5723524

于 2021-09-02T14:39:00.300 回答