aws / aws/aws-sam-cli-app-templates

Cache layer with docker to speed up the development workflow

Open
#242 2 comments 0 reactions 0 assignees View on GitHub
area/build area/docker stage/pm-review type/feature
Dominant language
Python
Stars
534
Forks
264
PR merge metrics
No merged PRs in 30d

Description

### Describe your idea/feature/enhancement
[Project: `sam init - python 3.8 - image container `(not zip file)]
`sam build` always rebuild the image even if:
- `requirements.txt` is not changed
- the code is not changed

### Proposal
At least in development, we could change to Dockerfile to cache the layers that didn't changed, such as requirments.txt. When someone has a slow connection, it take A LOT of time.

In order to do this, the default Dockerfile should be changed in:
**New** `Dockerfile`
```
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"]
```

**Old** `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"]
```

### Additional Details

Contributor guide

Open the contributing guide

Research direction

Start by locating the default Dockerfile used by `sam init` for the Python 3.8 image-container project, then compare its COPY and pip-install layers with the proposed Dockerfile. Check how `sam build` uses this template and identify the relevant template tests, if present. Done means unchanged requirements and source can reuse Docker cache during development without changing the generated application's behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
build-system, devops
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.