fast-belgium-77939
05/10/2023, 10:10 PMdocker_image(
name="aws_py39_pex_builder",
instructions=[
"FROM public.ecr.aws/lambda/python:3.9",
"RUN yum -y update && yum -y install some list of build packages",
... # Some unfun ENV shenanigans
],
)
docker_environment(
name="aws_lambda_py39",
image="aws_py39_pex_builder",
)
pex_binary(
name="entrypoint",
dependencies=["./entrypoint.py"], # this brings all sorts of nasty python packages
environment="aws_lambda_py39",
)
docker_image(
name="lambda",
dependencies=[":entrypoint"],
instructions=[
"FROM public.ecr.aws/lambda/python:3.9",
"RUN yum -y update && yum -y install some runtime packages",
... # more fun stuff
"COPY path.to.package/entrypoint.pex /build/entrypoint.pex",
"RUN unzip /build/entrypoint.pex -d \"${LAMBDA_TASK_ROOT}\"",
"CMD [\"__pex__.path.to.package.entrypoint.handle\"]",
],
... # some metadata for tags and stuff here
)
My current big question / worry is that I can’t seem to find a way of making aws_lambda_py39 depend on aws_py39_pex_builder. Thus, I’m exploring a couple of options:
1. Run pants package :aws_py39_pex_builder followed by pants package :lambda, manually, wherever we need to.
2. Run a simple “check_and_build_maybe” function in .pants.bootstrap as a remediative step that carries out either pants package :aws_py30_pex_builder or docker build … (likely the latter).
Am I missing a simpler way of solving this problem? Have I missed a glaringly obvious bit in the docs that would fix this problem for me? If not, and if I were to hypothetically look into adding a dependencies field to docker_environment, how much trouble would I likely get myself into?broad-processor-92400
05/10/2023, 10:17 PMdocker_image can't be used as an environment yet: https://github.com/pantsbuild/pants/issues/17714
For 2, I do suspect that recursively calling pants in .pants.bootstrap might fork-bomb your machine, so a direct docker build might be necessary.
BTW, we also deploy lambdas (as zips) and to ECS, although we get away without running in environments by using complete platforms (all of our deps are either Python-only or provided as wheels, and you may not be so lucky!): https://github.com/pantsbuild/pants/discussions/18756 has a bunch of notes about it.fast-belgium-77939
05/10/2023, 10:24 PM• We’d prefer to deploy dependencies in a layer and then only our first-party source in the direct lambda packageNot sure how far you got on this, but you and @average-breakfast-91545 should chat 🙂
broad-processor-92400
05/10/2023, 10:27 PMpex3 venv create --layout=flat-zipped functionality, and then https://github.com/pantsbuild/pants/issues/18880 after that, as, hopefully, a small incremental step.broad-processor-92400
05/23/2023, 11:24 PMaverage-breakfast-91545
05/24/2023, 8:50 AMbroad-processor-92400
05/30/2023, 5:50 AM