I have created an LLM agent with tools using Langchain and Python. I build my Lambda with with AWS SAM with Docker. After building, I test the Docker image using sam local invoke, and the Lambda function executes as expected (on M1 Max chip), using Langchain's Playwright toolkit to navigate a headless, asynchronous chromium browser. After I deploy with SAM, I test the function in the AWS Lambda UI, but there is an issue with navigating the browser: Target page, context or browser has been closed. I do not experience this error when testing the lambda locally with sam local invoke.
Additionally, if the LLM agent does not use Playwright tools, then the Lambda executes as expected. This confirms that there is an issue using Playwright (via the Langchain package) within a deployed AWS Lambda function that is not experienced with local testing.
- Used image with Playwright in Dockerfile: mcr.microsoft.com/playwright/python:v1.21.0-focal. Expected Playwright browsers to properly configured. Browser still closes prematurely.
- Increased to 2048 MB. I hoped that more memory might solve the issue, but error still occurs.
- Followed this guide for Dockerfile. I thought by adding aws-lambda-cpp build dependencies the issue might resolve, but it did not.
- Tried
--platform=linux/x86_64and--platform=linux/arm64with Playwright image.Architectureset in Docker to correspond to choice. Error still occurs.