<#19256 Allow Lambda targets to point to `python_a...
# github-notifications
c
#19256 Allow Lambda targets to point to `python_aws_lambda_layer`s and exclude code automatically Issue created by huonw Is your feature request related to a problem? Please describe. In #19123, Pants grows support for
python_aws_lambda_layer
to package layers for AWS Lambda. These are a bunch of code that's loaded into the Lambda environment, in addition to the core package. When packaging an in-repo layer for use with in-repo functions, typically the function doesn't need to include the code in the layer. Pants could automatically manage this, without needing to specify
include_requirements=False
and/or
dependencies=["!!foo", "!!bar"]
. Describe the solution you'd like Potentially a
layers
field that takes a list of layer targets. To begin with, this can be just used for excluding the dependencies. This field can be used on both functions and other layers. (NB. a package built like this is cannot be used in isolation, only with the right layers hooked into the deployed function in AWS.) For instance, in this example: •
boto3-layer
includes the
boto3
library and its dependencies, like
requests
func
depends on
boto3
,
requests
and
numpy
The
layers
field means pants would notice that
boto3
(and, preferably, its transitive dependencies like
requests
, which may require #12733) will already be provided by
boto3-layer
, and thus only include
numpy
and
foo.py
in the
func
package.
Copy code
# BUILD
python_requirements(name="reqs") # includes boto3, requests, numpy, etc.

python_aws_lambda_layer(
    name="boto3-layer"
    dependencies=[":reqs#boto3"],
    ...
)

python_aws_lambda_function(
    name="func",
    handler="./foo.py:handler",
    layers=[":boto3-layer"], # NEW FEATURE
    ...
)
Copy code
# foo.py
import boto3
import requests
import numpy

def handler(...): ...
Describe alternatives you've considered The current approach of manually spelling out dependencies and exclusions probably works fine for many cases, e.g. a naive "requirements in a layer"/"sources in the function" split is trivial via `include_requirements`/`include_sources`. Additional context There's a long discussion in #19123 that touches on this. pantsbuild/pants