Adding playwright to docker image using AWS lambda project - .Net Core C#. (empty function blueprint)

0

Hi,

I was able to create a lambda function using AWS lambda project - .Net Core C#. (empty function blueprint) and turn it into a docker image. Now the entry point is correctly set and also I was able to add playwright to the image. But, when I try to launch a chromium brower in the lambda. I am getting the following error:- "errorType": "TargetClosedException", pid=42\n[pid=42][err] /ms-playwright/chromium-1112/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

  • [pid=42][err] /ms-playwright/chromium-1112/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

Did anyone run into this issue before? here is the docker file that I have:- FROM mcr.microsoft.com/dotnet/sdk:8.0-jammy as base ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright RUN mkdir /ms-playwright &&
cd /ms-playwright &&
pwsh -Command "dotnet new console" &&
echo '<?xml version="1.0" encoding="utf-8"?><configuration><packageSources><add key="local" value="/tmp/"/></packageSources></configuration>' > nuget.config &&
pwsh -Command "dotnet add package Microsoft.Playwright" &&
pwsh -Command "dotnet add package AWSSDK.S3" &&
pwsh -Command "dotnet build" &&
pwsh -Command "./bin/Debug/net8.0/playwright.ps1 install --with-deps" &&
apt-get update &&
apt-get install -y \libnss3 &&
rm -rf /var/lib/apt/lists/* &&
rm -rf /tmp/* &&
chmod -R 777 /ms-playwright

Use the specified .NET SDK image as the build image

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src

Copy the project file and restore dependencies

COPY ["AWSLambdaURLToPDFPOC.csproj", "base/"] RUN dotnet restore "base/AWSLambdaURLToPDFPOC.csproj"

Copy the rest of the source code

COPY . .

Build the app

WORKDIR "/src" RUN dotnet build "AWSLambdaURLToPDFPOC.csproj" --configuration Release --output /app/build

Publish the app

FROM build AS publish RUN dotnet publish "AWSLambdaURLToPDFPOC.csproj"
--configuration Release
--runtime linux-x64
--self-contained false
--output /app/publish
-p:PublishReadyToRun=true

Use the latest AWS Lambda .NET base image as the runtime image

FROM public.ecr.aws/lambda/dotnet:latest AS final WORKDIR /var/task

Copy the published app from the publish stage

COPY --from=publish /app/publish .

Copy Playwright installation from the base stage

COPY --from=base /ms-playwright /ms-playwright

Set permissions for Playwright

RUN chmod +x .playwright/node/*/node

Set the entry point for the Lambda function

CMD ["AWSLambdaURLToPDFPOC::AWSLambdaURLToPDFPOC.Function::FunctionHandler"]

As you can see, I have tried installing libnss3.so but no luck. Please feel free to ask for more information, and please suggest any other approaches that you think might work. I don't mind trying them out.

Indu
asked 16 days ago104 views
1 Answer
0

The steps being followed looks good to me. I am unsure what could be wrong in the installation. However, I would recommend below steps to isolate the issue

  1. Testing the image locally if possible https://docs.aws.amazon.com/lambda/latest/dg/csharp-image.html
  2. Try to build layers for the libraries required. Please note .NET8 uses Amazon Linux 2023 as OS so it is recommended to use EC2 with Amazon Linux 2023 to build the layers. https://aws.amazon.com/blogs/compute/working-with-lambda-layers-and-extensions-in-container-images/
  3. You can also cut a support case and work with an engineer over screenshare. Please note support engineers might not be able to help a lot with code due to scope of support. However, they will be happy to help to the best of their knowledge. https://docs.aws.amazon.com/awssupport/latest/user/case-management.html#creating-a-support-case
  4. Highly recommend opening a github issue here https://github.com/aws/aws-lambda-dotnet/issues I will be happy to escalate the github to Lambda developers internally to give their insights.
AWS
SUPPORT ENGINEER
answered 8 days ago
profile picture
EXPERT
reviewed 6 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions