【问题标题】:Unable to load shared library 'libgdiplus' or one of its dependencies while running lambda function运行 lambda 函数时无法加载共享库“libgdiplus”或其依赖项之一
【发布时间】:2021-12-02 22:35:16
【问题描述】:

我正在 .NET Core 3.1 中编写 AWS Lambda 函数。我在 AWS Lambda 函数中使用 Aspose.slides 库。我将 AWS lambda 函数发布为 AWS 上的 docker。 Lambda 函数成功发布,但是当我测试 Lambda 时,它给了我以下错误:

Aspose.Slides.PptxReadException: The type initializer for 'Gdip' threw an exception.
---> System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
---> System.DllNotFoundException: Unable to load shared library 'libgdiplus' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibgdiplus: cannot open shared object file: No such file or directory
at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
at System.Drawing.SafeNativeMethods.Gdip..cctor()

尽管,我正在从 docker 文件安装 libgdiplus 包,但我仍然收到上述错误。

Docker 文件是:

FROM public.ecr.aws/lambda/dotnet:core3.1 AS base  

FROM mcr.microsoft.com/dotnet/sdk:3.1 as build  
WORKDIR /src  
COPY ["Lambda.PowerPointProcessor.csproj", "base/"]  
RUN dotnet restore "base/Lambda.PowerPointProcessor.csproj"  
  
WORKDIR "/src"  
COPY . .  
RUN apt-get update && apt-get install -y libc6-dev
RUN apt-get update && apt-get install -y libgdiplus
RUN dotnet build "Lambda.PowerPointProcessor.csproj" --configuration Release --output /app/build  
  
FROM build AS publish  
RUN dotnet publish "Lambda.PowerPointProcessor.csproj" \  
            --configuration Release \   
            --runtime linux-x64 \  
            --self-contained false \   
            --output /app/publish \  
            -p:PublishReadyToRun=true    
  
FROM base AS final  
WORKDIR /var/task  
COPY --from=publish /app/publish .  
CMD ["Lambda.PowerPointProcessor::Lambda.PowerPointProcessor.Function::FunctionHandler"]

任何帮助将不胜感激。

【问题讨论】:

  • 我面临同样的问题。有什么解决办法吗?
  • @SayedUzZaman 为我解决问题的 docker 文件已发布为答案。
  • 我正在使用 mcr.microsoft.com/dotnet/core/aspnet:3.1 AS 运行时,在我的情况下应该怎么做?任何提示都会有所帮助。

标签: amazon-web-services docker aws-lambda dockerfile asp.net-core-3.1


【解决方案1】:
FROM public.ecr.aws/lambda/dotnet:core3.1

WORKDIR /var/task

COPY "bin/Release/netcoreapp3.1/linux-x64"  .

RUN yum install -y amazon-linux-extras 
RUN amazon-linux-extras install epel -y
RUN yum install -y libgdiplus  

CMD ["Lambda.PowerPointProcessor::Lambda.PowerPointProcessor.Function::FunctionHandler"]

这个 docker 文件为我解决了这个问题。对我来说效果很好。

【讨论】:

    猜你喜欢
    • 2019-12-02
    • 2022-10-24
    • 2021-06-15
    • 2023-02-16
    • 2020-07-11
    • 1970-01-01
    • 2012-09-15
    • 2018-08-21
    • 1970-01-01
    相关资源
    最近更新 更多