From 5a717b2801d33cc9a96494e19304cdecc9d05ec4 Mon Sep 17 00:00:00 2001 From: Philip Pittle Date: Fri, 1 Nov 2024 17:29:59 -0700 Subject: [PATCH 1/2] Add support for enabling SnapStart with deploy-function and update-function-config commands. --- .../Amazon.Lambda.Tools.csproj | 2 +- .../Commands/DeployFunctionCommand.cs | 13 ++++++++++++ .../Commands/GetFunctionConfigCommand.cs | 6 ++++++ .../Commands/UpdateFunctionConfigCommand.cs | 20 +++++++++++++++++++ .../LambdaDefinedCommandOptions.cs | 11 +++++++++- .../Amazon.Lambda.Tools.Test.csproj | 2 +- 6 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/Amazon.Lambda.Tools/Amazon.Lambda.Tools.csproj b/src/Amazon.Lambda.Tools/Amazon.Lambda.Tools.csproj index 8a24804..f16fbad 100644 --- a/src/Amazon.Lambda.Tools/Amazon.Lambda.Tools.csproj +++ b/src/Amazon.Lambda.Tools/Amazon.Lambda.Tools.csproj @@ -37,7 +37,7 @@ - + diff --git a/src/Amazon.Lambda.Tools/Commands/DeployFunctionCommand.cs b/src/Amazon.Lambda.Tools/Commands/DeployFunctionCommand.cs index d346f28..e5ec667 100644 --- a/src/Amazon.Lambda.Tools/Commands/DeployFunctionCommand.cs +++ b/src/Amazon.Lambda.Tools/Commands/DeployFunctionCommand.cs @@ -85,6 +85,8 @@ public class DeployFunctionCommand : UpdateFunctionConfigCommand LambdaDefinedCommandOptions.ARGUMENT_LOG_APPLICATION_LEVEL, LambdaDefinedCommandOptions.ARGUMENT_LOG_SYSTEM_LEVEL, LambdaDefinedCommandOptions.ARGUMENT_LOG_GROUP, + + LambdaDefinedCommandOptions.ARGUMENT_SNAP_START_APPLY_ON }); public string Architecture { get; set; } @@ -181,6 +183,9 @@ protected override void ParseCommandArguments(CommandOptions values) this.ContainerImageForBuild = tuple.Item2.StringValue; if ((tuple = values.FindCommandOption(LambdaDefinedCommandOptions.ARGUMENT_CODE_MOUNT_DIRECTORY.Switch)) != null) this.CodeMountDirectory = tuple.Item2.StringValue; + + if ((tuple = values.FindCommandOption(LambdaDefinedCommandOptions.ARGUMENT_SNAP_START_APPLY_ON.Switch)) != null) + this.SnapStartApplyOn = tuple.Item2.StringValue; } @@ -424,6 +429,11 @@ protected override async Task PerformActionAsync() createRequest.TracingConfig = new TracingConfig { Mode = tracingMode }; } + var snapStartApplyOn = this.GetStringValueOrDefault(this.SnapStartApplyOn, LambdaDefinedCommandOptions.ARGUMENT_SNAP_START_APPLY_ON, false); + if (!string.IsNullOrEmpty(snapStartApplyOn)) + { + createRequest.SnapStart = new SnapStart {ApplyOn = Amazon.Lambda.SnapStartApplyOn.FindValue(snapStartApplyOn)}; + } try { @@ -639,6 +649,9 @@ protected override void SaveConfigFile(JsonData data) data.SetIfNotNull(LambdaDefinedCommandOptions.ARGUMENT_LOG_APPLICATION_LEVEL.ConfigFileKey, this.GetStringValueOrDefault(this.LogApplicationLevel, LambdaDefinedCommandOptions.ARGUMENT_LOG_APPLICATION_LEVEL, false)); data.SetIfNotNull(LambdaDefinedCommandOptions.ARGUMENT_LOG_SYSTEM_LEVEL.ConfigFileKey, this.GetStringValueOrDefault(this.LogSystemLevel, LambdaDefinedCommandOptions.ARGUMENT_LOG_SYSTEM_LEVEL, false)); data.SetIfNotNull(LambdaDefinedCommandOptions.ARGUMENT_LOG_GROUP.ConfigFileKey, this.GetStringValueOrDefault(this.LogGroup, LambdaDefinedCommandOptions.ARGUMENT_LOG_GROUP, false)); + + data.SetIfNotNull(LambdaDefinedCommandOptions.ARGUMENT_SNAP_START_APPLY_ON.ConfigFileKey, this.GetStringValueOrDefault(this.SnapStartApplyOn, LambdaDefinedCommandOptions.ARGUMENT_SNAP_START_APPLY_ON, false)); + } } } diff --git a/src/Amazon.Lambda.Tools/Commands/GetFunctionConfigCommand.cs b/src/Amazon.Lambda.Tools/Commands/GetFunctionConfigCommand.cs index 50aa715..b76333f 100644 --- a/src/Amazon.Lambda.Tools/Commands/GetFunctionConfigCommand.cs +++ b/src/Amazon.Lambda.Tools/Commands/GetFunctionConfigCommand.cs @@ -116,6 +116,12 @@ protected override async Task PerformActionAsync() this.Logger.WriteLine("Dead Letter Target:".PadRight(PAD_SIZE) + response.DeadLetterConfig.TargetArn); } + if (!string.IsNullOrEmpty(response.SnapStart?.ApplyOn?.Value)) + { + this.Logger.WriteLine("SnapStart"); + this.Logger.WriteLine(" Apply On:".PadRight(PAD_SIZE) + response.SnapStart.ApplyOn.Value); + this.Logger.WriteLine(" Optimization Status:".PadRight(PAD_SIZE) + response.SnapStart?.OptimizationStatus?.Value ?? ""); + } if (response.Environment?.Variables?.Count > 0) { diff --git a/src/Amazon.Lambda.Tools/Commands/UpdateFunctionConfigCommand.cs b/src/Amazon.Lambda.Tools/Commands/UpdateFunctionConfigCommand.cs index b884fe6..161c276 100644 --- a/src/Amazon.Lambda.Tools/Commands/UpdateFunctionConfigCommand.cs +++ b/src/Amazon.Lambda.Tools/Commands/UpdateFunctionConfigCommand.cs @@ -60,6 +60,8 @@ public class UpdateFunctionConfigCommand : LambdaBaseCommand LambdaDefinedCommandOptions.ARGUMENT_LOG_APPLICATION_LEVEL, LambdaDefinedCommandOptions.ARGUMENT_LOG_SYSTEM_LEVEL, LambdaDefinedCommandOptions.ARGUMENT_LOG_GROUP, + + LambdaDefinedCommandOptions.ARGUMENT_SNAP_START_APPLY_ON }); public string FunctionName { get; set; } @@ -97,6 +99,7 @@ public class UpdateFunctionConfigCommand : LambdaBaseCommand public string LogApplicationLevel { get; set; } public string LogSystemLevel { get; set; } public string LogGroup { get; set; } + public string SnapStartApplyOn { get; set; } public UpdateFunctionConfigCommand(IToolLogger logger, string workingDirectory, string[] args) @@ -181,6 +184,9 @@ protected override void ParseCommandArguments(CommandOptions values) this.LogSystemLevel = tuple.Item2.StringValue; if ((tuple = values.FindCommandOption(LambdaDefinedCommandOptions.ARGUMENT_LOG_GROUP.Switch)) != null) this.LogGroup = tuple.Item2.StringValue; + + if ((tuple = values.FindCommandOption(LambdaDefinedCommandOptions.ARGUMENT_SNAP_START_APPLY_ON.Switch)) != null) + this.SnapStartApplyOn = tuple.Item2.StringValue; } @@ -703,6 +709,20 @@ private UpdateFunctionConfigurationRequest CreateConfigurationRequestIfDifferent } } + var snapStartApplyOn = this.GetStringValueOrDefault(this.SnapStartApplyOn, LambdaDefinedCommandOptions.ARGUMENT_SNAP_START_APPLY_ON, false); + if (!string.IsNullOrEmpty(snapStartApplyOn)) + { + if (null == request.SnapStart) + request.SnapStart = new SnapStart(); + + if (!string.Equals(existingConfiguration?.SnapStart?.ApplyOn?.Value, snapStartApplyOn, StringComparison.Ordinal)) + { + request.SnapStart.ApplyOn = snapStartApplyOn; + different = true; + } + } + + if (!different) return null; diff --git a/src/Amazon.Lambda.Tools/LambdaDefinedCommandOptions.cs b/src/Amazon.Lambda.Tools/LambdaDefinedCommandOptions.cs index fbf40ed..7df2b81 100644 --- a/src/Amazon.Lambda.Tools/LambdaDefinedCommandOptions.cs +++ b/src/Amazon.Lambda.Tools/LambdaDefinedCommandOptions.cs @@ -4,7 +4,7 @@ namespace Amazon.Lambda.Tools { /// /// This class defines all the possible options across all the commands. The individual commands will then - /// references the options that are appropiate. + /// references the options that are appropriate. /// public static class LambdaDefinedCommandOptions { @@ -522,5 +522,14 @@ public static class LambdaDefinedCommandOptions ValueType = CommandOption.CommandOptionValueType.StringValue, Description = $"The name of the Amazon CloudWatch log group the function sends logs to. Default is /aws/lambda/." }; + public static readonly CommandOption ARGUMENT_SNAP_START_APPLY_ON = + new CommandOption + { + Name = "SnapStart Apply On", + Switch = "--snap-start-apply-on", + ShortSwitch = "-sa", + ValueType = CommandOption.CommandOptionValueType.StringValue, + Description = "Configure when a snapshot of the initialized execution environment should be taken. Valid values are: PublishedVersions, None. Default is None.", + }; } } diff --git a/test/Amazon.Lambda.Tools.Test/Amazon.Lambda.Tools.Test.csproj b/test/Amazon.Lambda.Tools.Test/Amazon.Lambda.Tools.Test.csproj index 80b0d15..108e14f 100644 --- a/test/Amazon.Lambda.Tools.Test/Amazon.Lambda.Tools.Test.csproj +++ b/test/Amazon.Lambda.Tools.Test/Amazon.Lambda.Tools.Test.csproj @@ -56,7 +56,7 @@ - + From 0be524676706e754daec5989f39c546b8870cc44 Mon Sep 17 00:00:00 2001 From: Norm Johanson Date: Mon, 18 Nov 2024 14:29:42 -0800 Subject: [PATCH 2/2] Version bump Amazon.Lambda.Tools to 5.12.0 --- CHANGELOG.md | 5 +++++ src/Amazon.Lambda.Tools/Amazon.Lambda.Tools.csproj | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3f641a..64ecb51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Release 2024-11-18 + +### Amazon.Lambda.Tools (5.12.0) +* Added `--snap-start-apply-on` switch to enable Lambda SnapStart + ## Release 2024-11-01 ### Amazon.Lambda.Tools (5.11.1) diff --git a/src/Amazon.Lambda.Tools/Amazon.Lambda.Tools.csproj b/src/Amazon.Lambda.Tools/Amazon.Lambda.Tools.csproj index 5ac5d9c..c53fe76 100644 --- a/src/Amazon.Lambda.Tools/Amazon.Lambda.Tools.csproj +++ b/src/Amazon.Lambda.Tools/Amazon.Lambda.Tools.csproj @@ -15,7 +15,7 @@ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. AWS Lambda Tools for .NET CLI false - 5.11.1 + 5.12.0