aws / aws/aws-sam-cli

Allow multiple CodeUris for a function

Open
#1,257 3 comments 9 reactions 0 assignees View on GitHub
area/bestpractices area/build maintainer/need-followup type/feature type/ux
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

Most of my SAM applications have a handful of functions and overall contain a small amount of code. I have started putting that code all together and deploying it to each function (that is, all functions use the same CodeUri), distinguishing code paths between functions by different handlers in the code. I opened #1236 because the SAM CLI should build the code once and copy the built code for every function.

I'd like to go beyond this "one zip file per application" approach by having some separate code per function, but also allowing a lightweight way of sharing some code between functions in the same application (i.e., template). Layers seem like the wrong abstraction for this; they are useful when the lifecycle of the code they contain is independent of the lifecycle of the code in the functions that use them, but in this case, the lifecycle of the function code and the shared code is one and the same.

How I'd like to enable this code sharing is by having multiple CodeUris in my SAM template. `sam build` would produce the zip as the overlay of the results, so the packaged template would still end up with a single (S3) CodeUri. I'm not sure whether I want the build step to happen separately or after the overlay; my primary goal in choosing one or the other would be reducing build times.

Using this functionality, when building my application, I'd have directories for each of my functions, and a shared directory (again, these are all tightly coupled). Developing in Python, I'd add these directories my `PYTHONPATH`, so in development my IDE would still understand the code correctly even though it is laid out differently than in the zip file. I would be responsible for making sure one directory wasn't clobbering another in the overlay process.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.