[英]Is there a way to incrementally build container images with AWS SAM?
我使用部署为容器映像的 AWS SAM CLI 创建了一个 Lambda function。 问题是每次我对代码 (app.py) 进行小的更改并运行sam build时,都会下载需求。 从下面的Dockerfile可以理解原因。
Dockerfile
FROM public.ecr.aws/lambda/python:3.8
COPY app.py requirements.txt ./
COPY models /opt/ml/models
RUN python3.8 -m pip install -r requirements.txt -t .
CMD ["app.lambda_handler"]
每次我运行sam build时它都会下载需求。
我还在 github 上遇到了一个使用--cached选项的线程,但如果我们使用容器映像,它就不起作用。 https://github.com/aws/aws-sam-cli/issues/805
模板.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Timeout: 50
MemorySize: 5000
Resources:
InferenceFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
PackageType: Image
Architectures:
- x86_64
Metadata:
Dockerfile: Dockerfile
DockerContext: ./app
DockerTag: python3.8-v1
依赖项是 tensorflow 2.8.0,超过 200MB,我无法更改为任何其他选项,如 tensorflow-lite。
通过 docker 缓存的工作方式,您的COPY
语句之后的所有内容都在缓存中无效(假设更改)。 依赖项通常保留在缓存中的方式是仅添加安装依赖项所必需的内容,安装它们,然后仅在安装依赖项后添加您的服务代码。 在下面的示例中, pip install
只会在 requirements.txt 更改时运行多次。
FROM public.ecr.aws/lambda/python:3.8
COPY requirements.txt ./
RUN python3.8 -m pip install -r requirements.txt -t .
COPY app.py ./
COPY models /opt/ml/models
CMD ["app.lambda_handler"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.