Hi, I am trying to use Pants to publish images for...
# general
m
Hi, I am trying to use Pants to publish images for an AWS Lambda function to AWS ECR. Testing the Lambda function I noticed that it just ends in a timeout without any errors, so I assume that probably nothing has really been executed. I suspect that is has something to do with the entrypoint and that AWS somehow cannot execute anything. Here is the corresponding part of my Dockerfile
Copy code
...
# Add Lambda Runtime Interface Emulator and use a script in the ENTRYPOINT for simpler local runs
ADD <https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie> /usr/bin/aws-lambda-rie
COPY services/${SERVICE}/lambda_entrypoint.sh /
RUN chmod 755 /usr/bin/aws-lambda-rie /lambda_entrypoint.sh

ENTRYPOINT [ "/lambda_entrypoint.sh" ]
CMD [ "lambdex_handler.handler" ]
where my entrypoint script looks as follows:
Copy code
#!/bin/sh
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
    exec /usr/bin/aws-lambda-rie /usr/local/bin/python -m awslambdaric $1
else
    exec /usr/local/bin/python -m awslambdaric $1
fi
The BUILD file:
Copy code
python_awslambda(
    name="function-lambda",
    runtime="python3.8",
    handler="lambda_handler.py:handler",
)

docker_image(
    name="function-image-ecr",
    dependencies=[
        ":function-lambda",
        ":entrypoint",
    ],
    image_tags=["image_tag"],
    tags=["ecr"],
    repository="repo_name",
)

file(
    name="entrypoint",
    source="lambda_entrypoint.sh",
)

python_sources()
The pants.toml contains:
Copy code
...
backend_packages = [
  'pants.backend.python',
  "pants.backend.awslambda.python",...
]
...
Are there obvious mistakes in my configuration that would explain the problem on AWS?
g
Lambda's default timeout is 3 seconds, did you modify that value? Is that enough for your function to execute?
m
I am using Pulumi to configurate the Lambdas and then a pants Github Actions worflow to publish the images. In the configuration of my Lambda I set the timeout to 300s and I can see in the Logs at AWS that it starts and ends 5 minutes later (without any logs in between although I have many of them in my handler). I guess my function needs more than 3s but not much more. Do I have to configure the timeout also somewhere in the Pants config?
g
I presume this isn't a pants issue as all it does is to package your code into a zipfile. If the entrypoint were wrong you'd see an error immediately. The fact you're not seeing logs could be related to the lambda's role not having permission to write them? And if the function is quick but takes that much time, could it be timing out in e.g. trying to connect to a db? Just guessing :)
b
Does it run locally? For timeouts, pants-side config won’t influence the runtime timeouts.