Feature request: Support custom manifest hash function for specific logical id
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
Description
### Describe your idea/feature/enhancement
I wish SAM cli would support custom manifest hash function for specific logical id. Currently there is no way to specify hash functions in this manner. The command `sam build --manifest ` is used to specify the custom manifest file for the build. However for specific use case such as deploying multiple lambda functions/layers with different dependencies, it is not currently possible.
#### Here's our use case:-
Assuming we have a template with multiple lambda layers as below:-
```yaml
MyLayer1:
Type: AWS::Serverless::LayerVersion
Metadata:
BuildMethod: makefile
BuildArchitecture: amd64
Properties:
ContentUri: layercontents/
RetentionPolicy: Delete
Description: Common Dependencies for monolith analyser
CompatibleArchitectures:
- x86_64
CompatibleRuntimes:
- python3.10
```
This layer will only contain dependencies from [poetry group](https://python-poetry.org/docs/master/managing-dependencies/#dependency-groups) layer1. We use the following layer to build the layer.
```makefile
build-MyLayer1:
mkdir -p "$(ARTIFACTS_DIR)/python"
poetry export --only=layer1 --format=requirements.txt > $(ARTIFACTS_DIR)/requirements.txt
python3.10 -m pip install -r $(ARTIFACTS_DIR)/requirements.txt -t "$(ARTIFACTS_DIR)/python" \
--implementation cp --platform manylinux2014_x86_64 --only-binary=:all: --
```
And then we use the following command to build the layer.
```bash
sam build --cached
```
The issue is whenever our pyproject.toml or poetry.lock file changes, all the layers will be rebuilt. We want only the layers where the dependencies have changed to be rebuilt.
### Proposal
#### Proposal 1:-
There can be a field in the makefile which can be used to generate the manifest hash. For example:-
```makefile
manifesthash-MyLayer1:
poetry export --only=layer1 --format=requirements.txt | md5sum > $(ARTIFACTS_DIR)/.manifesthash
```
And then the sam template can check whether the hash file has changed or not. If it has not changed, then it can skip the build process.
#### Proposal 2:-
There may be a custom metadata field. For example:-
```yaml
MyLayer1:
Type: AWS::Serverless::LayerVersion
Metadata:
BuildMethod: makefile
BuildArchitecture: amd64
BuildManifestHashCliCommand: poetry export --only=layer1 --format=requirements.txt | md5sum
...
```
Things to consider:
1. Will this require any updates to the [SAM Spec](https://github.com/awslabs/serverless-application-model): Unlikely
### Additional Details
- Related issue: #2989
- This can serve as a temporary workaround until #1366 is fully implemented.
Contributor guide
Assessment
This issue has not been assessed yet.