Skip to content

Commit

Permalink
Update warning for ARM and AMD architectures on Amazon Linux (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
GarrettBeatty authored Nov 20, 2024
1 parent 7e156ef commit 21166cb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .autover/changes/5ce6e470-afe4-41e4-8945-ea5f9317d53d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Projects": [
{
"Name": "Amazon.Lambda.Tools",
"Type": "Patch",
"ChangelogMessages": [
"Updated message related to self-contained runtimes with lambda functions"
]
}
]
}
44 changes: 40 additions & 4 deletions src/Amazon.Lambda.Tools/LambdaPackager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ public static class LambdaPackager
private static bool IsAmazonLinux(IToolLogger logger)
{
#if !NETCOREAPP3_1_OR_GREATER
return false;
return false;
#else
return IsAmazonLinux2(logger) || IsAmazonLinux2023(logger);
#endif
}

private static bool IsAmazonLinux2(IToolLogger logger)
{
#if !NETCOREAPP3_1_OR_GREATER
return false;
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Expand All @@ -55,6 +64,24 @@ private static bool IsAmazonLinux(IToolLogger logger)
$"Linux distribution is Amazon Linux 2, NativeAOT container build is optional");
return true;
}
}
}

return false;
#endif
}

private static bool IsAmazonLinux2023(IToolLogger logger)
{
#if !NETCOREAPP3_1_OR_GREATER
return false;
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
if (File.Exists(LinuxOSReleaseFile))
{
logger?.WriteLine($"Found {LinuxOSReleaseFile}");
string readText = File.ReadAllText(LinuxOSReleaseFile);
if (readText.Contains(AmazonLinuxNameInOSReleaseFile) && readText.Contains(AmazonLinux2023InOSReleaseFile))
{
logger?.WriteLine(
Expand Down Expand Up @@ -110,10 +137,19 @@ public static bool CreateApplicationBundle(LambdaToolsDefaults defaults, IToolLo

LogDeprecationMessagesIfNecessary(logger, targetFramework);

if (string.Equals(architecture, LambdaConstants.ARCHITECTURE_ARM64) && msbuildParameters != null && msbuildParameters.Contains("--self-contained true"))
if (msbuildParameters != null && msbuildParameters.Contains("--self-contained true"))
{
logger.WriteLine("WARNING: There is an issue with self contained ARM based .NET Lambda functions using custom runtimes that causes functions to fail to run. The following GitHub issue has further information and workaround.");
logger.WriteLine("https://github.com/aws/aws-lambda-dotnet/issues/920");
if (string.Equals(architecture, LambdaConstants.ARCHITECTURE_ARM64) && IsAmazonLinux2(logger))
{
logger.WriteLine("WARNING: There is an issue with self-contained ARM-based .NET Lambda functions using custom runtimes on Amazon Linux 2 that causes functions to fail to run.");
logger.WriteLine("For more information and workarounds, see: https://github.com/aws/aws-lambda-dotnet/issues/920");
}
else if (IsAmazonLinux2023(logger))
{
logger.WriteLine("WARNING: There is an issue with self-contained .NET Lambda functions using custom runtimes on Amazon Linux 2023 that causes functions to fail to run.");
logger.WriteLine("This applies to both AMD and ARM architectures.");
logger.WriteLine("For more information and workarounds, see: https://github.com/aws/aws-lambda-dotnet/issues/920");
}
}

if (string.IsNullOrEmpty(configuration))
Expand Down

0 comments on commit 21166cb

Please sign in to comment.