Skip to content

Commit

Permalink
feat: add dotnet8 support (#6429) (#6723)
Browse files Browse the repository at this point in the history
* feat: add dotnet8 support (#6429)

* feat: add dotnet8 support

* Update dotnet8 test dependencies and remove extra using directives

* Update samcli/lib/utils/preview_runtimes.py

---------

Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com>

* update schema

* add dotnet8 to runtime_supported_by_docker in test utils

---------

Co-authored-by: Beau Gosse <bgosse@amazon.com>
Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 21, 2024
1 parent 73e47ab commit e961128
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ tests/integration/testdata/buildcmd/Dotnet6/bin
tests/integration/testdata/buildcmd/Dotnet6/obj
tests/integration/testdata/buildcmd/Dotnet7/bin
tests/integration/testdata/buildcmd/Dotnet7/obj
tests/integration/testdata/buildcmd/Dotnet8/bin
tests/integration/testdata/buildcmd/Dotnet8/obj
tests/integration/testdata/invoke/credential_tests/inprocess/dotnet/STS/obj
tests/integration/testdata/sync/code/after/dotnet_function/src/HelloWorld/obj/
tests/integration/testdata/sync/code/before/dotnet_function/src/HelloWorld/obj/
Expand Down
2 changes: 1 addition & 1 deletion samcli/commands/build/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
2. Nodejs 20.x, 18.x, 16.x, 14.x, 12.x using NPM\n
3. Ruby 3.2 using Bundler\n
4. Java 8, Java 11, Java 17, Java 21 using Gradle and Maven\n
5. Dotnet6 using Dotnet CLI (without --use-container)\n
5. Dotnet8, Dotnet6 using Dotnet CLI\n
6. Go 1.x using Go Modules (without --use-container)\n
"""

Expand Down
2 changes: 2 additions & 0 deletions samcli/lib/build/workflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def get_layer_subfolder(build_workflow: str) -> str:
"java17": "java",
"java21": "java",
"dotnet6": "dotnet",
"dotnet8": "dotnet",
# User is responsible for creating subfolder in these workflows
"makefile": "",
}
Expand Down Expand Up @@ -161,6 +162,7 @@ def get_workflow_config(
"nodejs20.x": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"ruby3.2": BasicWorkflowSelector(RUBY_BUNDLER_CONFIG),
"dotnet6": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
"dotnet8": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
"go1.x": BasicWorkflowSelector(GO_MOD_CONFIG),
# When Maven builder exists, add to this list so we can automatically choose a builder based on the supported
# manifest
Expand Down
1 change: 1 addition & 0 deletions samcli/lib/utils/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"java21": [ARM64, X86_64],
"go1.x": [X86_64],
"dotnet6": [ARM64, X86_64],
"dotnet8": [ARM64, X86_64],
"provided": [X86_64],
"provided.al2": [ARM64, X86_64],
"provided.al2023": [ARM64, X86_64],
Expand Down
6 changes: 5 additions & 1 deletion samcli/local/common/runtime_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
],
"dotnet": [
{
"runtimes": ["dotnet6"],
"runtimes": ["dotnet8", "dotnet6"],
"dependency_manager": "cli-package",
"init_location": os.path.join(_templates, "cookiecutter-aws-sam-hello-dotnet"),
"build": True,
Expand Down Expand Up @@ -99,7 +99,9 @@ def get_local_lambda_images_location(mapping, runtime):
# Runtimes are ordered in alphabetical fashion with reverse version order (latest versions first)
INIT_RUNTIMES = [
# dotnet runtimes in descending order
"dotnet8",
"dotnet6",
# go runtimes in descending order
"go1.x",
# java runtimes in descending order
"java21",
Expand Down Expand Up @@ -127,6 +129,7 @@ def get_local_lambda_images_location(mapping, runtime):


LAMBDA_IMAGES_RUNTIMES_MAP = {
"dotnet8": "amazon/dotnet8-base",
"dotnet6": "amazon/dotnet6-base",
"go1.x": "amazon/go1.x-base",
"go (provided.al2)": "amazon/go-provided.al2-base",
Expand Down Expand Up @@ -164,6 +167,7 @@ def get_local_lambda_images_location(mapping, runtime):
"python3.11": "Python36",
"python3.12": "Python36",
"dotnet6": "dotnet6",
"dotnet8": "dotnet6",
"go1.x": "Go1",
}

Expand Down
4 changes: 4 additions & 0 deletions samcli/local/docker/lambda_debug_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def get_debug_settings(debug_port, debug_args_list, _container_env_vars, runtime
entry + ["/var/runtime/bootstrap"] + debug_args_list,
container_env_vars={"_AWS_LAMBDA_DOTNET_DEBUGGING": "1", **_container_env_vars},
),
Runtime.dotnet8.value: lambda: DebugSettings(
entry + ["/var/runtime/bootstrap"] + debug_args_list,
container_env_vars={"_AWS_LAMBDA_DOTNET_DEBUGGING": "1", **_container_env_vars},
),
Runtime.go1x.value: lambda: DebugSettings(
entry,
container_env_vars={
Expand Down
1 change: 1 addition & 0 deletions samcli/local/docker/lambda_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Runtime(Enum):
java21 = "java21"
go1x = "go1.x"
dotnet6 = "dotnet6"
dotnet8 = "dotnet8"
provided = "provided"
providedal2 = "provided.al2"
providedal2023 = "provided.al2023"
Expand Down
8 changes: 5 additions & 3 deletions schema/samcli.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"properties": {
"parameters": {
"title": "Parameters for the init command",
"description": "Available parameters for the init command:\n* no_interactive:\nDisable interactive prompting for init parameters. (fail if any required values are missing)\n* architecture:\nArchitectures for Lambda functions.\n\nArchitectures: ['arm64', 'x86_64']\n* location:\nTemplate location (git, mercurial, http(s), zip, path).\n* runtime:\nLambda runtime for application.\n\nRuntimes: dotnet6, go1.x, java21, java17, java11, java8.al2, java8, nodejs20.x, nodejs18.x, nodejs16.x, provided, provided.al2, provided.al2023, python3.9, python3.8, python3.12, python3.11, python3.10, ruby3.2\n* package_type:\nLambda deployment package type.\n\nPackage Types: Zip, Image\n* base_image:\nLambda base image for deploying IMAGE based package type.\n\nBase images: amazon/dotnet6-base, amazon/go-provided.al2-base, amazon/go-provided.al2023-base, amazon/go1.x-base, amazon/java11-base, amazon/java17-base, amazon/java21-base, amazon/java8-base, amazon/java8.al2-base, amazon/nodejs16.x-base, amazon/nodejs18.x-base, amazon/nodejs20.x-base, amazon/python3.10-base, amazon/python3.11-base, amazon/python3.12-base, amazon/python3.8-base, amazon/python3.9-base, amazon/ruby3.2-base\n* dependency_manager:\nDependency manager for Lambda runtime.\n\nDependency managers: bundler, cli-package, gradle, maven, mod, npm, pip\n* output_dir:\nDirectory to initialize AWS SAM application.\n* name:\nName of AWS SAM Application.\n* app_template:\nIdentifier of the managed application template to be used. Alternatively, run '$sam init' without options for an interactive workflow.\n* no_input:\nDisable Cookiecutter prompting and accept default values defined in the cookiecutter config.\n* extra_context:\nOverride custom parameters in the template's cookiecutter.json configuration e.g. {\"customParam1\": \"customValue1\", \"customParam2\":\"customValue2\"}\n* tracing:\nEnable AWS X-Ray tracing for application.\n* application_insights:\nEnable CloudWatch Application Insights monitoring for application.\n* structured_logging:\nEnable Structured Logging for application.\n* beta_features:\nEnable/Disable beta features.\n* debug:\nTurn on debug logging to print debug message generated by AWS SAM CLI and display timestamps.\n* save_params:\nSave the parameters provided via the command line to the configuration file.",
"description": "Available parameters for the init command:\n* no_interactive:\nDisable interactive prompting for init parameters. (fail if any required values are missing)\n* architecture:\nArchitectures for Lambda functions.\n\nArchitectures: ['arm64', 'x86_64']\n* location:\nTemplate location (git, mercurial, http(s), zip, path).\n* runtime:\nLambda runtime for application.\n\nRuntimes: dotnet8, dotnet6, go1.x, java21, java17, java11, java8.al2, java8, nodejs20.x, nodejs18.x, nodejs16.x, provided, provided.al2, provided.al2023, python3.9, python3.8, python3.12, python3.11, python3.10, ruby3.2\n* package_type:\nLambda deployment package type.\n\nPackage Types: Zip, Image\n* base_image:\nLambda base image for deploying IMAGE based package type.\n\nBase images: amazon/dotnet6-base, amazon/dotnet8-base, amazon/go-provided.al2-base, amazon/go-provided.al2023-base, amazon/go1.x-base, amazon/java11-base, amazon/java17-base, amazon/java21-base, amazon/java8-base, amazon/java8.al2-base, amazon/nodejs16.x-base, amazon/nodejs18.x-base, amazon/nodejs20.x-base, amazon/python3.10-base, amazon/python3.11-base, amazon/python3.12-base, amazon/python3.8-base, amazon/python3.9-base, amazon/ruby3.2-base\n* dependency_manager:\nDependency manager for Lambda runtime.\n\nDependency managers: bundler, cli-package, gradle, maven, mod, npm, pip\n* output_dir:\nDirectory to initialize AWS SAM application.\n* name:\nName of AWS SAM Application.\n* app_template:\nIdentifier of the managed application template to be used. Alternatively, run '$sam init' without options for an interactive workflow.\n* no_input:\nDisable Cookiecutter prompting and accept default values defined in the cookiecutter config.\n* extra_context:\nOverride custom parameters in the template's cookiecutter.json configuration e.g. {\"customParam1\": \"customValue1\", \"customParam2\":\"customValue2\"}\n* tracing:\nEnable AWS X-Ray tracing for application.\n* application_insights:\nEnable CloudWatch Application Insights monitoring for application.\n* structured_logging:\nEnable Structured Logging for application.\n* beta_features:\nEnable/Disable beta features.\n* debug:\nTurn on debug logging to print debug message generated by AWS SAM CLI and display timestamps.\n* save_params:\nSave the parameters provided via the command line to the configuration file.",
"type": "object",
"properties": {
"no_interactive": {
Expand All @@ -48,9 +48,10 @@
"runtime": {
"title": "runtime",
"type": "string",
"description": "Lambda runtime for application.\n\nRuntimes: dotnet6, go1.x, java21, java17, java11, java8.al2, java8, nodejs20.x, nodejs18.x, nodejs16.x, provided, provided.al2, provided.al2023, python3.9, python3.8, python3.12, python3.11, python3.10, ruby3.2",
"description": "Lambda runtime for application.\n\nRuntimes: dotnet8, dotnet6, go1.x, java21, java17, java11, java8.al2, java8, nodejs20.x, nodejs18.x, nodejs16.x, provided, provided.al2, provided.al2023, python3.9, python3.8, python3.12, python3.11, python3.10, ruby3.2",
"enum": [
"dotnet6",
"dotnet8",
"go1.x",
"java11",
"java17",
Expand Down Expand Up @@ -83,9 +84,10 @@
"base_image": {
"title": "base_image",
"type": "string",
"description": "Lambda base image for deploying IMAGE based package type.\n\nBase images: amazon/dotnet6-base, amazon/go-provided.al2-base, amazon/go-provided.al2023-base, amazon/go1.x-base, amazon/java11-base, amazon/java17-base, amazon/java21-base, amazon/java8-base, amazon/java8.al2-base, amazon/nodejs16.x-base, amazon/nodejs18.x-base, amazon/nodejs20.x-base, amazon/python3.10-base, amazon/python3.11-base, amazon/python3.12-base, amazon/python3.8-base, amazon/python3.9-base, amazon/ruby3.2-base",
"description": "Lambda base image for deploying IMAGE based package type.\n\nBase images: amazon/dotnet6-base, amazon/dotnet8-base, amazon/go-provided.al2-base, amazon/go-provided.al2023-base, amazon/go1.x-base, amazon/java11-base, amazon/java17-base, amazon/java21-base, amazon/java8-base, amazon/java8.al2-base, amazon/nodejs16.x-base, amazon/nodejs18.x-base, amazon/nodejs20.x-base, amazon/python3.10-base, amazon/python3.11-base, amazon/python3.12-base, amazon/python3.8-base, amazon/python3.9-base, amazon/ruby3.2-base",
"enum": [
"amazon/dotnet6-base",
"amazon/dotnet8-base",
"amazon/go-provided.al2-base",
"amazon/go-provided.al2023-base",
"amazon/go1.x-base",
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/buildcmd/test_build_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,8 @@ class TestBuildCommand_Dotnet_cli_package(BuildIntegBase):
("dotnet6", "Dotnet6", None),
("dotnet6", "Dotnet6", "debug"),
("provided.al2", "Dotnet7", None),
("dotnet8", "Dotnet8", None),
("dotnet8", "Dotnet8", "debug"),
]
)
def test_dotnet_in_process(self, runtime, code_uri, mode, architecture="x86_64"):
Expand Down Expand Up @@ -1272,6 +1274,8 @@ def test_dotnet_in_process(self, runtime, code_uri, mode, architecture="x86_64")
# force to run tests on arm64 machines may cause dotnet7 test failing
# because Native AOT Lambda functions require the host and lambda architectures to match
("provided.al2", "Dotnet7", None),
("dotnet8", "Dotnet8", None),
("dotnet8", "Dotnet8", "debug"),
]
)
@skipIf(SKIP_DOCKER_TESTS or SKIP_DOCKER_BUILD, SKIP_DOCKER_MESSAGE)
Expand Down Expand Up @@ -1344,6 +1348,8 @@ def test_dotnet_in_container_mount_with_write_explicit(self, runtime, code_uri,
# force to run tests on arm64 machines may cause dotnet7 test failing
# because Native AOT Lambda functions require the host and lambda architectures to match
("provided.al2", "Dotnet7", None),
("dotnet8", "Dotnet8", None),
("dotnet8", "Dotnet8", "debug"),
]
)
@skipIf(SKIP_DOCKER_TESTS or SKIP_DOCKER_BUILD, SKIP_DOCKER_MESSAGE)
Expand Down Expand Up @@ -1413,7 +1419,7 @@ def test_dotnet_in_container_mount_with_write_interactive(
)
self.verify_docker_container_cleanedup(runtime)

@parameterized.expand([("dotnet6", "Dotnet6")])
@parameterized.expand([("dotnet6", "Dotnet6"), ("dotnet8", "Dotnet8")])
@skipIf(SKIP_DOCKER_TESTS or SKIP_DOCKER_BUILD, SKIP_DOCKER_MESSAGE)
def test_must_fail_on_container_mount_without_write_interactive(self, runtime, code_uri):
use_container = True
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/testdata/buildcmd/Dotnet8/HelloWorld.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
36 changes: 36 additions & 0 deletions tests/integration/testdata/buildcmd/Dotnet8/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Amazon.Lambda.Core;
using Amazon.Lambda.APIGatewayEvents;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

namespace HelloWorld
{

public class Function
{

public string FunctionHandler(APIGatewayProxyRequest apigProxyEvent, ILambdaContext context)
{
return "{'message': 'Hello World'}";
}
}

public class FirstFunction
{

public string FunctionHandler(APIGatewayProxyRequest apigProxyEvent, ILambdaContext context)
{
return "Hello World";
}
}

public class SecondFunction
{

public string FunctionHandler(APIGatewayProxyRequest apigProxyEvent, ILambdaContext context)
{
return "Hello Mars";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"Information" : [
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",

"dotnet lambda help",

"All the command line options for the Lambda command can be specified in this file."
],

"profile":"",
"region" : "",
"configuration": "Release",
"framework": "net8.0",
"function-runtime":"dotnet8",
"function-memory-size" : 256,
"function-timeout" : 30,
"function-handler" : "HelloWorld::HelloWorld.Function::FunctionHandler"
}
1 change: 1 addition & 0 deletions tests/integration/validate/test_validate_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def test_lint_supported_runtimes(self):
"Resources": {},
}
supported_runtimes = [
"dotnet8",
"dotnet6",
"go1.x",
"java21",
Expand Down
1 change: 1 addition & 0 deletions tests/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def runtime_supported_by_docker(runtime: str) -> bool:
"nodejs20.x",
"java21",
"python3.12",
"dotnet8",
}
min_docker_version = "20.10.10"
return runtime not in al2023_based_runtimes or (
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/local/docker/test_lambda_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from samcli.local.docker.lambda_debug_settings import DebuggingNotSupported
from samcli.local.docker.lambda_image import RAPID_IMAGE_TAG_PREFIX

RUNTIMES_WITH_ENTRYPOINT = [Runtime.dotnet6.value, Runtime.go1x.value]
RUNTIMES_WITH_ENTRYPOINT = [Runtime.dotnet6.value, Runtime.dotnet8.value, Runtime.go1x.value]

RUNTIMES_WITH_BOOTSTRAP_ENTRYPOINT = [
Runtime.nodejs16x.value,
Expand All @@ -26,6 +26,7 @@
Runtime.python311.value,
Runtime.python312.value,
Runtime.dotnet6.value,
Runtime.dotnet8.value,
]

RUNTIMES_WITH_DEBUG_ENV_VARS_ONLY = [
Expand Down
1 change: 1 addition & 0 deletions tests/unit/local/docker/test_lambda_debug_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Runtime.java17,
Runtime.java21,
Runtime.dotnet6,
Runtime.dotnet8,
Runtime.go1x,
Runtime.nodejs16x,
Runtime.nodejs18x,
Expand Down
1 change: 1 addition & 0 deletions tests/unit/local/docker/test_lambda_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class TestRuntime(TestCase):
("java21", "java:21-x86_64"),
("go1.x", "go:1"),
("dotnet6", "dotnet:6-x86_64"),
("dotnet8", "dotnet:8-x86_64"),
("provided", "provided:alami"),
("provided.al2", "provided:al2-x86_64"),
("provided.al2023", "provided:al2023-x86_64"),
Expand Down

0 comments on commit e961128

Please sign in to comment.