From c13391da90fc3e49ba4927a988c23c5da53a9d2d Mon Sep 17 00:00:00 2001 From: Beau Gosse Date: Thu, 10 Nov 2022 19:14:53 -0600 Subject: [PATCH 1/5] feat: add dotnet7 build method (#428) * # This is a combination of 2 commits. # This is the 1st commit message: Add dotnet7 build method for provided * Added 'BuildMethod: dotnet7' using 'Runtime:provided' * 'Runtime:provided' is only for the provided runtime and not the dotnet runtime Testing with sample SAM template: ( See BuildMethod and Runtime below ) ... HelloWorldFunction: Type: AWS::Serverless::Function Metadata: BuildMethod: dotnet7 Properties: CodeUri: ./src/HelloWorld/ Handler: HelloWorld::HelloWorld.Function::FunctionHandler Runtime: provided Architectures: - x86_64 ... # This is the commit message #2: Add dotnet7 build method for provided * Added 'BuildMethod: dotnet7' using 'Runtime:provided' * 'Runtime:provided' is only for the provided runtime and not the dotnet runtime Testing with sample SAM template: ( See BuildMethod and Runtime below ) ... HelloWorldFunction: Type: AWS::Serverless::Function Metadata: BuildMethod: dotnet7 Properties: CodeUri: ./src/HelloWorld/ Handler: HelloWorld::HelloWorld.Function::FunctionHandler Runtime: provided Architectures: - x86_64 ... * run black reformat Co-authored-by: Samiullah Mohammed Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com> Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> --- .gitignore | 2 + samcli/lib/build/workflow_config.py | 5 ++- tests/integration/buildcmd/test_build_cmd.py | 16 +++++++- .../buildcmd/Dotnet7/HelloWorld.csproj | 25 ++++++++++++ .../testdata/buildcmd/Dotnet7/Program.cs | 38 +++++++++++++++++++ .../Dotnet7/aws-lambda-tools-defaults.json | 18 +++++++++ .../testdata/buildcmd/Dotnet7/rd.xml | 6 +++ .../template_build_method_dotnet_7.yaml | 38 +++++++++++++++++++ .../lib/build_module/test_workflow_config.py | 11 ++++++ 9 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 tests/integration/testdata/buildcmd/Dotnet7/HelloWorld.csproj create mode 100755 tests/integration/testdata/buildcmd/Dotnet7/Program.cs create mode 100644 tests/integration/testdata/buildcmd/Dotnet7/aws-lambda-tools-defaults.json create mode 100644 tests/integration/testdata/buildcmd/Dotnet7/rd.xml create mode 100644 tests/integration/testdata/buildcmd/template_build_method_dotnet_7.yaml diff --git a/.gitignore b/.gitignore index 501d092293..14fd530d9f 100644 --- a/.gitignore +++ b/.gitignore @@ -409,6 +409,8 @@ tests/integration/testdata/buildcmd/Dotnetcore3.1/bin tests/integration/testdata/buildcmd/Dotnetcore3.1/obj 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/invoke/credential_tests/inprocess/dotnet/STS/obj # End of https://www.gitignore.io/api/osx,node,macos,linux,python,windows,pycharm,intellij,sublimetext,visualstudiocode diff --git a/samcli/lib/build/workflow_config.py b/samcli/lib/build/workflow_config.py index d6b1f55926..ead6490367 100644 --- a/samcli/lib/build/workflow_config.py +++ b/samcli/lib/build/workflow_config.py @@ -140,7 +140,10 @@ def get_workflow_config( namedtuple that represents the Builder Workflow Config """ - selectors_by_build_method = {"makefile": BasicWorkflowSelector(PROVIDED_MAKE_CONFIG)} + selectors_by_build_method = { + "makefile": BasicWorkflowSelector(PROVIDED_MAKE_CONFIG), + "dotnet7": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG), + } selectors_by_runtime = { "python3.6": BasicWorkflowSelector(PYTHON_PIP_CONFIG), diff --git a/tests/integration/buildcmd/test_build_cmd.py b/tests/integration/buildcmd/test_build_cmd.py index 8289dc741b..20236dc66e 100644 --- a/tests/integration/buildcmd/test_build_cmd.py +++ b/tests/integration/buildcmd/test_build_cmd.py @@ -950,7 +950,6 @@ class TestBuildCommand_Dotnet_cli_package(BuildIntegBase): FUNCTION_LOGICAL_ID = "Function" EXPECTED_FILES_PROJECT_MANIFEST = { "Amazon.Lambda.APIGatewayEvents.dll", - "HelloWorld.pdb", "Amazon.Lambda.Core.dll", "HelloWorld.runtimeconfig.json", "Amazon.Lambda.Serialization.Json.dll", @@ -959,12 +958,17 @@ class TestBuildCommand_Dotnet_cli_package(BuildIntegBase): "HelloWorld.dll", } + EXPECTED_FILES_PROJECT_MANIFEST_PROVIDED = { + "bootstrap", + } + @parameterized.expand( [ ("dotnetcore3.1", "Dotnetcore3.1", None), ("dotnet6", "Dotnet6", None), ("dotnetcore3.1", "Dotnetcore3.1", "debug"), ("dotnet6", "Dotnet6", "debug"), + ("provided", "Dotnet7", None), ] ) @pytest.mark.flaky(reruns=3) @@ -975,6 +979,10 @@ def test_with_dotnetcore(self, runtime, code_uri, mode, architecture="x86_64"): "Handler": "HelloWorld::HelloWorld.Function::FunctionHandler", "Architectures": architecture, } + + if runtime == "provided": + self.template_path = self.template_path.replace("template.yaml", "template_build_method_dotnet_7.yaml") + cmdlist = self.get_command_list(use_container=False, parameter_overrides=overrides) LOG.info("Running Command: {}".format(cmdlist)) @@ -987,7 +995,11 @@ def test_with_dotnetcore(self, runtime, code_uri, mode, architecture="x86_64"): run_command(cmdlist, cwd=self.working_dir, env=newenv) self._verify_built_artifact( - self.default_build_dir, self.FUNCTION_LOGICAL_ID, self.EXPECTED_FILES_PROJECT_MANIFEST + self.default_build_dir, + self.FUNCTION_LOGICAL_ID, + self.EXPECTED_FILES_PROJECT_MANIFEST + if runtime != "provided" + else self.EXPECTED_FILES_PROJECT_MANIFEST_PROVIDED, ) self._verify_resource_property( diff --git a/tests/integration/testdata/buildcmd/Dotnet7/HelloWorld.csproj b/tests/integration/testdata/buildcmd/Dotnet7/HelloWorld.csproj new file mode 100644 index 0000000000..23eedf4416 --- /dev/null +++ b/tests/integration/testdata/buildcmd/Dotnet7/HelloWorld.csproj @@ -0,0 +1,25 @@ + + + + net7.0 + true + true + true + exe + bootstrap + enable + + + + + + + + + + + + + + + diff --git a/tests/integration/testdata/buildcmd/Dotnet7/Program.cs b/tests/integration/testdata/buildcmd/Dotnet7/Program.cs new file mode 100755 index 0000000000..da7d128ea6 --- /dev/null +++ b/tests/integration/testdata/buildcmd/Dotnet7/Program.cs @@ -0,0 +1,38 @@ +using Amazon.Lambda.APIGatewayEvents; +using Amazon.Lambda.Core; +using Amazon.Lambda.RuntimeSupport; +using Amazon.Lambda.Serialization.SystemTextJson; +using System.Text.Json.Serialization; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Net.Http; +using System.Net.Http.Headers; + +namespace HelloWorld; + +public class Function +{ + /// + /// The main entry point for the custom runtime. + /// + /// + private static async Task Main(string[] args) + { + Func handler = FunctionHandler; + await LambdaBootstrapBuilder.Create(handler, new SourceGeneratorLambdaJsonSerializer()) + .Build() + .RunAsync(); + } + + public static string FunctionHandler(APIGatewayHttpApiV2ProxyRequest apigProxyEvent, ILambdaContext context) + { + return "{'message': 'Hello World'}"; + } +} + +[JsonSerializable(typeof(APIGatewayHttpApiV2ProxyRequest))] +public partial class MyCustomJsonSerializerContext : JsonSerializerContext +{ +} diff --git a/tests/integration/testdata/buildcmd/Dotnet7/aws-lambda-tools-defaults.json b/tests/integration/testdata/buildcmd/Dotnet7/aws-lambda-tools-defaults.json new file mode 100644 index 0000000000..4e29f8dc4c --- /dev/null +++ b/tests/integration/testdata/buildcmd/Dotnet7/aws-lambda-tools-defaults.json @@ -0,0 +1,18 @@ +{ + "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", + "function-runtime":"provided", + "function-memory-size" : 256, + "function-timeout" : 30, + "function-handler" : "HelloWorld::HelloWorld.Function::FunctionHandler" +} diff --git a/tests/integration/testdata/buildcmd/Dotnet7/rd.xml b/tests/integration/testdata/buildcmd/Dotnet7/rd.xml new file mode 100644 index 0000000000..6d35e8768c --- /dev/null +++ b/tests/integration/testdata/buildcmd/Dotnet7/rd.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tests/integration/testdata/buildcmd/template_build_method_dotnet_7.yaml b/tests/integration/testdata/buildcmd/template_build_method_dotnet_7.yaml new file mode 100644 index 0000000000..4902db2fa9 --- /dev/null +++ b/tests/integration/testdata/buildcmd/template_build_method_dotnet_7.yaml @@ -0,0 +1,38 @@ +iAWSTemplateFormatVersion : '2010-09-09' +Transform: AWS::Serverless-2016-10-31 + +Parameteres: + Runtime: + Type: String + CodeUri: + Type: String + Handler: + Type: String + +Resources: + + Function: + Type: AWS::Serverless::Function + Properties: + Handler: !Ref Handler + Runtime: !Ref Runtime + CodeUri: !Ref CodeUri + Timeout: 600 + Metadata: + BuildMethod: dotnet7 + + OtherRelativePathResource: + Type: AWS::ApiGateway::RestApi + Properties: + BodyS3Location: SomeRelativePath + + GlueResource: + Type: AWS::Glue::Job + Properties: + Command: + ScriptLocation: SomeRelativePath + + ExampleNestedStack: + Type: AWS::CloudFormation::Stack + Properties: + TemplateURL: https://s3.amazonaws.com/examplebucket/exampletemplate.yml diff --git a/tests/unit/lib/build_module/test_workflow_config.py b/tests/unit/lib/build_module/test_workflow_config.py index e35d6c05fe..96914c6976 100644 --- a/tests/unit/lib/build_module/test_workflow_config.py +++ b/tests/unit/lib/build_module/test_workflow_config.py @@ -51,6 +51,17 @@ def test_must_work_for_provided(self, runtime): self.assertEqual(len(EventTracker.get_tracked_events()), 1) self.assertIn(Event("BuildWorkflowUsed", "provided-None"), EventTracker.get_tracked_events()) + @parameterized.expand([("provided",)]) + def test_must_work_for_provided_with_build_method_dotnet7(self, runtime): + result = get_workflow_config(runtime, self.code_dir, self.project_dir, specified_workflow="dotnet7") + self.assertEqual(result.language, "dotnet") + self.assertEqual(result.dependency_manager, "cli-package") + self.assertEqual(result.application_framework, None) + self.assertEqual(result.manifest_name, ".csproj") + self.assertIsNone(result.executable_search_paths) + self.assertEqual(len(EventTracker.get_tracked_events()), 1) + self.assertIn(Event("BuildWorkflowUsed", "dotnet-cli-package"), EventTracker.get_tracked_events()) + @parameterized.expand([("provided",)]) def test_must_work_for_provided_with_no_specified_workflow(self, runtime): # Implicitly look for makefile capability. From ed6286cac783fbee9d04ec7c6979a4b03e62a36f Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Mon, 14 Nov 2022 16:18:18 -0800 Subject: [PATCH 2/5] update provided with provided.al2 --- tests/integration/buildcmd/test_build_cmd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/buildcmd/test_build_cmd.py b/tests/integration/buildcmd/test_build_cmd.py index 35fe6a4a83..3b7441afee 100644 --- a/tests/integration/buildcmd/test_build_cmd.py +++ b/tests/integration/buildcmd/test_build_cmd.py @@ -969,7 +969,7 @@ class TestBuildCommand_Dotnet_cli_package(BuildIntegBase): ("dotnet6", "Dotnet6", None), ("dotnetcore3.1", "Dotnetcore3.1", "debug"), ("dotnet6", "Dotnet6", "debug"), - ("provided", "Dotnet7", None), + ("provided.al2", "Dotnet7", None), ] ) @pytest.mark.flaky(reruns=3) @@ -981,7 +981,7 @@ def test_with_dotnetcore(self, runtime, code_uri, mode, architecture="x86_64"): "Architectures": architecture, } - if runtime == "provided": + if runtime == "provided.al2": self.template_path = self.template_path.replace("template.yaml", "template_build_method_dotnet_7.yaml") cmdlist = self.get_command_list(use_container=False, parameter_overrides=overrides) From e97d5c3e5a4959d86f1887f388cd2774714b3e98 Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Mon, 14 Nov 2022 16:18:50 -0800 Subject: [PATCH 3/5] Update test_build_cmd.py --- tests/integration/buildcmd/test_build_cmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/buildcmd/test_build_cmd.py b/tests/integration/buildcmd/test_build_cmd.py index 3b7441afee..ea99af8836 100644 --- a/tests/integration/buildcmd/test_build_cmd.py +++ b/tests/integration/buildcmd/test_build_cmd.py @@ -999,7 +999,7 @@ def test_with_dotnetcore(self, runtime, code_uri, mode, architecture="x86_64"): self.default_build_dir, self.FUNCTION_LOGICAL_ID, self.EXPECTED_FILES_PROJECT_MANIFEST - if runtime != "provided" + if runtime != "provided.al2" else self.EXPECTED_FILES_PROJECT_MANIFEST_PROVIDED, ) From af6d1400858ec9204c34803474c71174f4789791 Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Mon, 14 Nov 2022 16:39:38 -0800 Subject: [PATCH 4/5] Update test_workflow_config.py --- tests/unit/lib/build_module/test_workflow_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/lib/build_module/test_workflow_config.py b/tests/unit/lib/build_module/test_workflow_config.py index 96914c6976..0c30fd9e32 100644 --- a/tests/unit/lib/build_module/test_workflow_config.py +++ b/tests/unit/lib/build_module/test_workflow_config.py @@ -51,7 +51,7 @@ def test_must_work_for_provided(self, runtime): self.assertEqual(len(EventTracker.get_tracked_events()), 1) self.assertIn(Event("BuildWorkflowUsed", "provided-None"), EventTracker.get_tracked_events()) - @parameterized.expand([("provided",)]) + @parameterized.expand([("provided.al2",)]) def test_must_work_for_provided_with_build_method_dotnet7(self, runtime): result = get_workflow_config(runtime, self.code_dir, self.project_dir, specified_workflow="dotnet7") self.assertEqual(result.language, "dotnet") From 810c7b81094be137411884c0dd8d5bd5a822d5fc Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Mon, 14 Nov 2022 16:41:03 -0800 Subject: [PATCH 5/5] Update aws-lambda-tools-defaults.json --- .../testdata/buildcmd/Dotnet7/aws-lambda-tools-defaults.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/testdata/buildcmd/Dotnet7/aws-lambda-tools-defaults.json b/tests/integration/testdata/buildcmd/Dotnet7/aws-lambda-tools-defaults.json index 4e29f8dc4c..15c8399a21 100644 --- a/tests/integration/testdata/buildcmd/Dotnet7/aws-lambda-tools-defaults.json +++ b/tests/integration/testdata/buildcmd/Dotnet7/aws-lambda-tools-defaults.json @@ -11,7 +11,7 @@ "profile":"", "region" : "", "configuration": "Release", - "function-runtime":"provided", + "function-runtime":"provided.al2", "function-memory-size" : 256, "function-timeout" : 30, "function-handler" : "HelloWorld::HelloWorld.Function::FunctionHandler"