skip to Main Content

I had a .Net6 Lambda working in AWS. Recently I changed it to adopt AOT using .Net7. After deploying to AWS I get below error on Lambda invocation:

/var/task/bootstrap: /lib64/libm.so.6: version `GLIBC_2.29' not found (required by /var/task/bootstrap)

here’s how the main part of my Function template looks like:

  Function:
    Type: AWS::Serverless::Function
    Metadata:
      BuildMethod: dotnet7
    Properties:
      FunctionName: upload-handler
      CodeUri: ./packages/upload-handler
      Handler: bootstrap
      Runtime: provided.al2
      Architectures:
      - x86_64

here’s my .csproject file:

  <Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <PublishAot>true</PublishAot>
    <AssemblyName>bootstrap</AssemblyName>
    <OutputType>Exe</OutputType>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <StripSymbols>true</StripSymbols>
    <TrimMode>partial</TrimMode>
    <AWSProjectType>Lambda</AWSProjectType>
    <Version>1.0.0</Version>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>

  <ItemGroup>
      <RdXmlFile Include="rd.xml" />
  </ItemGroup>
  <ItemGroup Condition="'$(RuntimeIdentifier)' == 'linux-arm64'">
    <RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="68.2.0.9" />
    <PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="68.2.0.9" />
  </ItemGroup>
  
  <ItemGroup>
    <PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.6.0" />
    <PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.8.7" />
    <PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.1" />
    <PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.5" />
    <PackageReference Include="AWSSDK.S3" Version="3.7.103.51" />
    <PackageReference Include="AWSSDK.SecretsManager" Version="3.7.102.26" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
    <PackageReference Include="Serilog" Version="2.12.0" />
    <PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
  </ItemGroup>

</Project>

and here’s the main parts of my dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:7.0

WORKDIR /app

# Install NativeAOT build prerequisites
RUN apt-get update && apt-get install -y --no-install-recommends clang zlib1g-dev
COPY ./src/Upload.Handler/*.csproj ./src/Upload.Handler/
COPY ./upload-handler.sln ./
RUN dotnet restore

COPY ./src/ ./src/
ARG VERSION
RUN dotnet publish ./src/Upload.Handler -r linux-x64 -c Release -o ./out/upload-handler /p:Version=$VERSION

When I run the Lambda locally using Docker there’s no issue with invoking.
I use docker-compose and aws cloudformation package to build and pack and aws cloudformation deploy to deploy to AWS.
I also use git pipeline CI/CD and the image used there for both build and deploy is ubuntu-latest

build:
  name: Build and Test
  runs-on: ubuntu-latest

My best guess is something is missed from dockerfile and I should go with multi-stage build using ubuntu-latest in dockerfile. Can someone please put me in the right direction.

2

Answers


  1. Chosen as BEST ANSWER

    I didn't end up with multi-stage docker file but I changed the image file to amazonlinux:2 along with some other changes which resolved the error. Below is my updated dockerfile:

    FROM public.ecr.aws/amazonlinux/amazonlinux:2 AS base
    
    WORKDIR /app
    
    # Install dotnet 7 and other dependencies for compiling natively
    RUN rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
    RUN yum update -y && yum install -y dotnet-sdk-7.0 clang krb5-devel openssl-devel zip
    
    COPY ./src/Upload.Handler/*.csproj ./src/Upload.Handler/
    COPY ./upload-handler.sln ./
    
    ENV DOTNET_NOLOGO=true
    ENV DOTNET_CLI_TELEMETRY_OPTOUT=true
    
    RUN dotnet restore
    
    COPY ./src/ ./src/
    ARG VERSION
    RUN dotnet publish ./src/Upload.Handler -r linux-x64 -c Release -o ./out/upload-handler /p:Version=$VERSION
    

  2. The error message /var/task/bootstrap: /lib64/libm.so.6: versionGLIBC_2.29′ not found (required by /var/task/bootstrap)` indicates that the Lambda function is trying to use a library that requires a newer version of the GNU C Library (glibc) than is available on the Lambda runtime.

    The Lambda runtime is based on Amazon Linux 2, which currently uses glibc 2.28. However, .NET 7 requires glibc 2.29 or newer.

    To fix this error, you can either:

    Update the Lambda runtime to a newer version that includes glibc 2.29.
    Build your .NET 7 application with the –no-supported-runtimes flag to disable the requirement for a supported runtime.
    Here are the steps on how to update the Lambda runtime to a newer version that includes glibc 2.29:

    Go to the AWS Management Console and open the Lambda service.
    Click on the "Functions" tab.
    Select the Lambda function that you want to update.
    Click on the "Configuration" tab.
    In the "Runtime" section, select "provided.al2".
    Click on the "Save" button.
    The Lambda function will be updated to the latest version of the provided.al2 runtime, which includes glibc 2.29.

    Here are the steps on how to build your .NET 7 application with the –no-supported-runtimes flag to disable the requirement for a supported runtime:

    Open a command prompt or terminal window.
    Navigate to the directory where your .NET 7 application is located.
    Run the following command:

    dotnet publish --no-supported-runtimes
    

    This will build your application without requiring a supported runtime.

    Once you have fixed the error, you should be able to deploy and invoke your Lambda function without any problems.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search