Anyone knows how to use PEX with custom lambda doc...
# general
r
Anyone knows how to use PEX with custom lambda docker image? https://pypi.org/project/awslambdaric/
I am not able to figure out what should I pass as CMD in the suggested dockerfile
Copy code
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
CMD [ "app.handler" ]
In the earlier thread @enough-analyst-54434 had it working with the AWS provided docker image https://pantsbuild.slack.com/archives/C046T6T9U/p1663436294507939?thread_ts=1663365806.280429&cid=C046T6T9U
Copy code
FROM public.ecr.aws/lambda/python:3.9

COPY project/lambda.zip ${LAMBDA_TASK_ROOT}
ENV PYTHONPATH ${LAMBDA_TASK_ROOT}/lambda.zip
CMD ["__pex__.lambda_example.example_handler"]
s
we set
entry_point="awslambdaric"
in our
pex_binary
target
😮 1
then in the Dockerfile we have:
Copy code
CMD ["./pex", "path.to.entrypoint" ]
r
I suppose you package awslambdaric inside the PEX itself?
s
yup! we have to set an explicit dependency on it too
for example:
Copy code
pex_binary(
    name="bin",
    dependencies=["//3rdparty/pants-only#awslambdaric", ":sources"],
    entry_point="awslambdaric",
)
🙌 1
r
Ah you have to set explicit dependencies on your sources too. Do your sources have explicit 1st party dependencies?
s
no, all the dependencies are inferred within the sources themselves
just have to help the pex_binary figure things out in this case since the entry-point isn’t in the 1st-party code
r
ah ok. That’s helpful
yes that’s where I was bit unsure
What pants/pex version are you using? I am getting error that
./pex
doesn’t exist
Copy code
IMAGE	Launch error: fork/exec ./pex: no such file or directory	Entrypoint: []	Cmd: [./pex,pyfleet_infra_planner.main.lambda_handler]	WorkingDir: [/function]
I am copying the pex binary inside /function.
wait is this the pex that is built? Should be ><
s
./pex
is where we copy the built pex into our image, but it is likely different based on your dockerfile
r
yes, just realized!! Thank you
So what kind of permissions (if any) you had to provide to run this pex @sparse-lifeguard-95737? I am getting permission denied error
Copy code
RequestId: 4149dea6-7501-4851-b51a-f3401fde334f Error: fork/exec ./service.pex: permission denied Runtime.InvalidEntrypoint