aws/aws-sam-cli

Bug: Dotnet 8 Container Image Arm64 Issue

Opened this issue · 3 comments

Description:

Getting non-zero code 139 when updating dotnet 6 docker file to dotnet 8, for container lambda functions, also occurs on sam init with hello world container lambda function creation.

Steps to reproduce:

sam init hello world, select container image type.

add "function-architecture": "arm64",

change build image to
FROM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim-arm64v8 AS build-image

delete Samconfig.toml

Change Template to include
Architectures:
- arm64

Observed result:

Error: The command '/bin/sh -c dotnet tool install -g Amazon.Lambda.Tools' returned a non-zero code: 139

Expected result:

sam build successfully.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

WSL2 Ubuntu 20.04 on Windows 11 24H2

  1. WSL2 Ubuntu 20.04 on Windows 11 24H2
  2. sam --version
  3. AWS region 'us-east-1'
# Paste the output of `sam --info` here
{
  "version": "1.127.0",
  "system": {
    "python": "3.11.10",
    "os": "Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.31"
  },
  "additional_dependencies": {
    "docker_engine": "27.2.1",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}


Still the same: 
2024-11-15 16:05:15,958 | Telemetry response: 200                                                                                                                                                                                                                                                                      
Error: The command '/bin/sh -c dotnet tool install -g Amazon.Lambda.Tools' returned a non-zero code: 139
2024-11-15 16:05:15,967 | Telemetry response: 200     

change build image to
FROM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim-arm64v8 AS build-image

Thanks for reporting this issue, may I ask why did you change the image before starting the build? Does building succeed if you use the original image?

No Sir, I still get the Exit code 139,

Okay, I think I was having trouble with the base Microsoft image and switched to the bullseye image for more stability.
Microsoft dumped debian bullseye for bookworm.

I tried building with just regular docker and got the below error:
=> => # qemu: uncaught target signal 11 (Segmentation fault) - core dumped

I updated QEMU running the command
sudo apt-get install -y qemu qemu-user-static

I built the package again for dotnet 8 and got the below:

Error: The command '/bin/sh -c if [ "$SAM_BUILD_MODE" = "debug" ]; then dotnet lambda package --configuration Debug; else dotnet lambda package --configuration Release; fi' returned a non-zero code: 255

I think QEMU binaries needed updated, troubleshooting this error now.

Well, I was not able to get this to run correctly as an arm64 image, I gave up and switched the function back to x86_64 and dotnet8, rather than dotnet6 and arm64/graviton.

I was able to build the function locally under arm64 using sam build, but running the command
"docker build --platform linux/arm64 -t my-lambda-function:arm64 ." In the project directory,
a Segfault appeared somewhere in QEMU and caused an issue.

This is the Error I'm getting:

24.68 Unhandled exception: System.NullReferenceException: Object reference not set to an instance of an object.
24.69 at Microsoft.Build.Evaluation.IntrinsicFunctions.IsOSPlatform(String platformString)
24.69 at Regex1_TryMatchAtCurrentPosition(RegexRunner, ReadOnlySpan1) 24.69 at System.Text.RegularExpressions.Regex.ScanInternal(RegexRunnerMode mode, Boolean reuseMatchObject, String input, Int32 beginning, RegexRunner runner, ReadOnlySpan1 span, Boolean returnNullIfReuseMatchObject)
24.69 at System.Text.RegularExpressions.Regex.RunAllMatchesWithCallback[TState](String inputString, ReadOnlySpan1 inputSpan, Int32 startat, TState& state, MatchCallback1 callback, RegexRunnerMode mode, Boolean reuseMatchObject)
24.69 at System.Text.RegularExpressions.Regex.RunAllMatchesWithCallback[TState](String input, Int32 startat, TState& state, MatchCallback1 callback, RegexRunnerMode mode, Boolean reuseMatchObject) 24.69 at System.Text.RegularExpressions.Regex.Replace(MatchEvaluator evaluator, Regex regex, String input, Int32 count, Int32 startat) 24.69 at Microsoft.Build.Evaluation.Expander2.MetadataExpander.ExpandMetadataLeaveEscaped(String expression, IMetadataTable metadata, ExpanderOptions options, IElementLocation elementLocation, LoggingContext loggingContext)
24.69 at Microsoft.Build.Evaluation.Expander2.ExpandIntoStringLeaveEscaped(String expression, ExpanderOptions options, IElementLocation elementLocation) 24.69 at Microsoft.Build.Evaluation.ConditionEvaluator.ConditionEvaluationState2.ExpandIntoStringBreakEarly(String expression)
24.69 at Microsoft.Build.Evaluation.StringExpressionNode.EvaluatesToEmpty(IConditionEvaluationState state)
24.69 at Microsoft.Build.Evaluation.MultipleComparisonNode.BoolEvaluate(IConditionEvaluationState state)
24.69 at Microsoft.Build.Evaluation.OperatorExpressionNode.TryBoolEvaluate(IConditionEvaluationState state, Boolean& result)
24.69 at Microsoft.Build.Evaluation.GenericExpressionNode.Evaluate(IConditionEvaluationState state)
24.69 at Microsoft.Build.Evaluation.ConditionEvaluator.EvaluateConditionCollectingConditionedProperties[P,I](String condition, ParserOptions options, Expander2 expander, ExpanderOptions expanderOptions, Dictionary2 conditionedPropertiesTable, String evaluationDirectory, ElementLocation elementLocation, IFileSystem fileSystem, LoggingContext loggingContext, ProjectRootElementCacheBase projectRootElementCache)
24.69 at Microsoft.Build.Evaluation.ConditionEvaluator.EvaluateCondition[P,I](String condition, ParserOptions options, Expander2 expander, ExpanderOptions expanderOptions, String evaluationDirectory, ElementLocation elementLocation, IFileSystem fileSystem, LoggingContext loggingContext, ProjectRootElementCacheBase projectRootElementCache) 24.69 at Microsoft.Build.Evaluation.LazyItemEvaluator4.EvaluateCondition(String condition, ProjectElement element, ExpanderOptions expanderOptions, ParserOptions parserOptions, Expander2 expander, LazyItemEvaluator4 lazyEvaluator)
24.69 at Microsoft.Build.Evaluation.LazyItemEvaluator4.LazyItemOperation.DecorateItemsWithMetadata(IEnumerable1 itemBatchingContexts, ImmutableArray1 metadata, Nullable1 needToExpandMetadata)
24.69 at Microsoft.Build.Evaluation.LazyItemEvaluator4.UpdateOperation.ApplyImpl(Builder listBuilder, ImmutableHashSet1 globsToIgnore)
24.69 at Microsoft.Build.Evaluation.LazyItemEvaluator4.LazyItemOperation.Apply(Builder listBuilder, ImmutableHashSet1 globsToIgnore)
24.69 at Microsoft.Build.Evaluation.LazyItemEvaluator4.LazyItemList.ComputeItems(LazyItemList lazyItemList, ImmutableHashSet1 globsToIgnore)
24.69 at Microsoft.Build.Evaluation.LazyItemEvaluator4.LazyItemList.GetItemData(ImmutableHashSet1 globsToIgnore)
24.69 at System.Linq.Enumerable.SelectManySingleSelectorIterator2.ToArray() 24.69 at System.Linq.Buffer1..ctor(IEnumerable1 source) 24.69 at System.Linq.OrderedEnumerable1.GetEnumerator()+MoveNext()
24.69 at Microsoft.Build.Evaluation.Evaluator4.Evaluate() 24.69 at Microsoft.Build.Evaluation.Evaluator4.Evaluate(IEvaluatorData4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary1 environmentProperties, ILoggingService loggingService, IItemFactory2 itemFactory, IToolsetProvider toolsetProvider, IDirectoryCacheFactory directoryCacheFactory, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive) 24.69 at Microsoft.Build.Evaluation.Project.ProjectImpl.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) 24.69 at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) 24.69 at Microsoft.Build.Evaluation.Project.ProjectImpl.Initialize(IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext, Boolean interactive)
24.69 at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext, IDirectoryCacheFactory directoryCacheFactory, Boolean interactive) 24.69 at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary2 globalProperties, String toolsVersion)
24.69 at Microsoft.Build.CommandLine.MSBuildApp.Execute(String[] commandLine)
24.69 at Microsoft.Build.CommandLine.MSBuildApp.Main(String[] args)
24.69 at Microsoft.DotNet.Cli.Utils.MSBuildForwardingAppWithoutLogging.ExecuteInProc(String[] arguments)
24.84 Executing publish command
24.85 ... invoking 'dotnet publish', working folder '/build/bin/Release/net8.0/publish'
25.39 ... dotnet publish "/build" --output "/build/bin/Release/net8.0/publish" --configuration "Release" --framework "net8.0" /p:GenerateRuntimeConfigurationFiles=true --runtime linux-arm64 --self-contained False
42.12 ... publish: Determining projects to restore...
42.14 ... publish: qemu: uncaught target signal 11 (Segmentation fault) - core dumped
76.83 ERROR: The dotnet publish command return unsuccessful error code

Here is my dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim-arm64v8 AS build-image

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-image

USER app

ARG FUNCTION_DIR="/build"
ARG SAM_BUILD_MODE="run"
ENV PATH="/root/.dotnet/tools:${PATH}"

RUN apt-get update && apt-get -y install zip

RUN mkdir $FUNCTION_DIR
WORKDIR $FUNCTION_DIR
COPY "Files" $FUNCTION_DIR/
RUN dotnet tool install -g Amazon.Lambda.Tools

Build and Copy artifacts depending on build mode.

RUN mkdir -p build_artifacts
RUN if [ "$SAM_BUILD_MODE" = "debug" ]; then dotnet lambda package --configuration Debug; else dotnet lambda package --configuration Release; fi
RUN if [ "$SAM_BUILD_MODE" = "debug" ]; then cp -r /build/bin/Debug/net8.0/publish/* /build/build_artifacts; else cp -r /build/bin/Release/net8.0/publish/* /build/build_artifacts; fi

FROM public.ecr.aws/lambda/dotnet:8-arm64

COPY --from=build-image /build/build_artifacts/ /var/task/

Command can be overwritten by providing a different command in the template directly.

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