Skip to content

Commit

Permalink
Merge branch 'feature/snapstart'
Browse files Browse the repository at this point in the history
  • Loading branch information
normj committed Nov 18, 2024
2 parents 21a1bec + 0be5246 commit 7e156ef
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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-08

### Amazon.Lambda.Tools (5.11.2)
Expand Down
4 changes: 2 additions & 2 deletions src/Amazon.Lambda.Tools/Amazon.Lambda.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Copyright>Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.</Copyright>
<Product>AWS Lambda Tools for .NET CLI</Product>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<Version>5.11.2</Version>
<Version>5.12.0</Version>
</PropertyGroup>
<ItemGroup>
<Content Include="Resources\build-lambda-zip.exe">
Expand All @@ -37,7 +37,7 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="AWSSDK.CloudFormation" Version="3.7.307.6" />
<PackageReference Include="AWSSDK.Lambda" Version="3.7.305.12" />
<PackageReference Include="AWSSDK.Lambda" Version="3.7.406.2" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.301.6" />
<PackageReference Include="AWSSDK.S3" Version="3.7.307.21" />
<PackageReference Include="YamlDotNet.Signed" Version="5.2.1" />
Expand Down
13 changes: 13 additions & 0 deletions src/Amazon.Lambda.Tools/Commands/DeployFunctionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -424,6 +429,11 @@ protected override async Task<bool> 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
{
Expand Down Expand Up @@ -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));

}
}
}
6 changes: 6 additions & 0 deletions src/Amazon.Lambda.Tools/Commands/GetFunctionConfigCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ protected override async Task<bool> 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)
{
Expand Down
20 changes: 20 additions & 0 deletions src/Amazon.Lambda.Tools/Commands/UpdateFunctionConfigCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -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;

Expand Down
11 changes: 10 additions & 1 deletion src/Amazon.Lambda.Tools/LambdaDefinedCommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Amazon.Lambda.Tools
{
/// <summary>
/// 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.
/// </summary>
public static class LambdaDefinedCommandOptions
{
Expand Down Expand Up @@ -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/<function name>."
};
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.",
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="AWSSDK.CloudFormation" Version="3.7.307.6" />
<PackageReference Include="AWSSDK.Lambda" Version="3.7.305.12" />
<PackageReference Include="AWSSDK.Lambda" Version="3.7.406.2" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.300.80" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
Expand Down

0 comments on commit 7e156ef

Please sign in to comment.