Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update warning for ARM and AMD architectures on Amazon Linux #347

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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