diff --git a/.github/workflows/source-generator-ci.yml b/.github/workflows/source-generator-ci.yml index 0cb96aa9c..e1fe6bc2d 100644 --- a/.github/workflows/source-generator-ci.yml +++ b/.github/workflows/source-generator-ci.yml @@ -1,33 +1,31 @@ -name: Source Generator CI +name: Lambda Annotations CI on: workflow_dispatch: push: branches: - - feature/annotations + - dev pull_request: jobs: - source-generator-build-pack-test: + lambda-annotations-build-pack-test: runs-on: ubuntu-latest - steps: - - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup .NET 3.1 - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: 3.1.x - name: Setup .NET 6.0 - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: 6.0.x - name: Setup .NET 8.0 - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.100-rc.2.23502.2 + dotnet-version: 8.0.x - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@8c3f20df09ac63af7b3ae3d7c91f105f857d8497 #v4 with: aws-access-key-id: ${{ secrets.CI_AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.CI_AWS_ACCESS_KEY_SECRET }} @@ -49,9 +47,9 @@ jobs: - name: Pack run: dotnet pack Libraries/src/Amazon.Lambda.Annotations/Amazon.Lambda.Annotations.csproj -p:NuspecFile=../Amazon.Lambda.Annotations.nuspec --no-build --configuration Release --output "PackResults" - name: Upload pack results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: source-generator-nuget-package + name: lambda-annotations-nuget-package path: PackResults # Use always() to always run this step to publish test results when there are test failures if: ${{ always() }} @@ -60,33 +58,31 @@ jobs: dotnet test Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj --no-build --configuration Release --verbosity normal --logger trx --results-directory "TestResults" dotnet test Libraries/test/TestServerlessApp.IntegrationTests/TestServerlessApp.IntegrationTests.csproj --no-build --configuration Release --verbosity normal --logger trx --results-directory "TestResults" - name: Upload test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: source-generator-test-result + name: lambda-annotations-test-result path: TestResults # Use always() to always run this step to publish test results when there are test failures if: ${{ always() }} test-app-build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup .NET 6.0 - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: 6.0.x - name: Setup .NET 8.0 - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.100-rc.2.23502.2 + dotnet-version: 8.0.x - name: Restore dependencies run: dotnet restore Libraries/test/TestServerlessApp/TestServerlessApp.csproj - name: Build run: dotnet build Libraries/test/TestServerlessApp/TestServerlessApp.csproj --no-restore --configuration Release --verbosity detailed - name: Upload built assemblies - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: test-app-build-result - path: Libraries/test/TestServerlessApp/bin/Debug/netcoreapp3.1 + path: Libraries/test/TestServerlessApp/bin/Release/net6.0 diff --git a/Libraries/Amazon.Lambda.Annotations.slnf b/Libraries/Amazon.Lambda.Annotations.slnf index 48c0cd6e0..1b89a7014 100644 --- a/Libraries/Amazon.Lambda.Annotations.slnf +++ b/Libraries/Amazon.Lambda.Annotations.slnf @@ -2,15 +2,16 @@ "solution": { "path": "Libraries.sln", "projects": [ + "src\\Amazon.Lambda.APIGatewayEvents\\Amazon.Lambda.APIGatewayEvents.csproj", "src\\Amazon.Lambda.Annotations.SourceGenerator\\Amazon.Lambda.Annotations.SourceGenerator.csproj", "src\\Amazon.Lambda.Annotations\\Amazon.Lambda.Annotations.csproj", - "src\\Amazon.Lambda.APIGatewayEvents\\Amazon.Lambda.APIGatewayEvents.csproj", - "src\\Amazon.Lambda.RuntimeSupport\\Amazon.Lambda.RuntimeSupport.csproj", "src\\Amazon.Lambda.Core\\Amazon.Lambda.Core.csproj", + "src\\Amazon.Lambda.RuntimeSupport\\Amazon.Lambda.RuntimeSupport.csproj", "src\\Amazon.Lambda.Serialization.SystemTextJson\\Amazon.Lambda.Serialization.SystemTextJson.csproj", "test\\Amazon.Lambda.Annotations.SourceGenerators.Tests\\Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj", - "test\\TestServerlessApp.IntegrationTests\\TestServerlessApp.IntegrationTests.csproj", "test\\TestExecutableServerlessApp\\TestExecutableServerlessApp.csproj", + "test\\TestServerlessApp.IntegrationTests\\TestServerlessApp.IntegrationTests.csproj", + "test\\TestServerlessApp.NET8\\TestServerlessApp.NET8.csproj", "test\\TestServerlessApp\\TestServerlessApp.csproj" ] } diff --git a/Libraries/Libraries.sln b/Libraries/Libraries.sln index 9879cb964..95e1c565d 100644 --- a/Libraries/Libraries.sln +++ b/Libraries/Libraries.sln @@ -130,14 +130,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Amazon.Lambda.LexV2Events", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest", "test\Amazon.Lambda.RuntimeSupport.Tests\CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest\CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest.csproj", "{0BD83939-458C-4EF5-8663-7098AD1200F2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestExecutableServerlessApp", "test\TestExecutableServerlessApp\TestExecutableServerlessApp.csproj", "{DD378063-C54A-44C7-9A6F-32A6A1AE94B3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestExecutableServerlessApp", "test\TestExecutableServerlessApp\TestExecutableServerlessApp.csproj", "{DD378063-C54A-44C7-9A6F-32A6A1AE94B3}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestServerlessApp.NET8", "test\TestServerlessApp.NET8\TestServerlessApp.NET8.csproj", "{7300983D-8FCE-42EA-9B9E-B1C5347D15D8}" EndProject Global - GlobalSection(SharedMSBuildProjectFiles) = preSolution - test\EventsTests.Shared\EventsTests.Shared.projitems*{44e9d925-b61d-4234-97b7-61424c963ba6}*SharedItemsImports = 5 - test\EventsTests.Shared\EventsTests.Shared.projitems*{a2cb78bb-e54f-48ca-bbfb-9553d27ef23d}*SharedItemsImports = 13 - test\EventsTests.Shared\EventsTests.Shared.projitems*{c1bb30d2-3237-4cfc-ba93-627471148ec2}*SharedItemsImports = 5 - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -359,6 +356,10 @@ Global {DD378063-C54A-44C7-9A6F-32A6A1AE94B3}.Debug|Any CPU.Build.0 = Debug|Any CPU {DD378063-C54A-44C7-9A6F-32A6A1AE94B3}.Release|Any CPU.ActiveCfg = Release|Any CPU {DD378063-C54A-44C7-9A6F-32A6A1AE94B3}.Release|Any CPU.Build.0 = Release|Any CPU + {7300983D-8FCE-42EA-9B9E-B1C5347D15D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7300983D-8FCE-42EA-9B9E-B1C5347D15D8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7300983D-8FCE-42EA-9B9E-B1C5347D15D8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7300983D-8FCE-42EA-9B9E-B1C5347D15D8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -422,8 +423,14 @@ Global {3C6AABF5-0372-41E0-874F-DF18ECCC7FB6} = {AAB54E74-20B1-42ED-BC3D-CE9F7BC7FD12} {0BD83939-458C-4EF5-8663-7098AD1200F2} = {B5BD0336-7D08-492C-8489-42C987E29B39} {DD378063-C54A-44C7-9A6F-32A6A1AE94B3} = {1DE4EE60-45BA-4EF7-BE00-B9EB861E4C69} + {7300983D-8FCE-42EA-9B9E-B1C5347D15D8} = {1DE4EE60-45BA-4EF7-BE00-B9EB861E4C69} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {503678A4-B8D1-4486-8915-405A3E9CF0EB} EndGlobalSection + GlobalSection(SharedMSBuildProjectFiles) = preSolution + test\EventsTests.Shared\EventsTests.Shared.projitems*{44e9d925-b61d-4234-97b7-61424c963ba6}*SharedItemsImports = 5 + test\EventsTests.Shared\EventsTests.Shared.projitems*{a2cb78bb-e54f-48ca-bbfb-9553d27ef23d}*SharedItemsImports = 13 + test\EventsTests.Shared\EventsTests.Shared.projitems*{c1bb30d2-3237-4cfc-ba93-627471148ec2}*SharedItemsImports = 5 + EndGlobalSection EndGlobal diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/AnalyzerReleases.Shipped.md b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/AnalyzerReleases.Shipped.md index d3c2bb2f4..e59823e20 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/AnalyzerReleases.Shipped.md +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/AnalyzerReleases.Shipped.md @@ -1,6 +1,16 @@ ; Shipped analyzer releases ; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md +## Release 1.1.0 +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|------- +AWSLambda0111 | AWSLambdaCSharpGenerator | Error | If the GenerateMain global property is set to true but the project OutputType is not set to 'exe' +AWSLambda0112 | AWSLambdaCSharpGenerator | Error | An invalid runtime is selected in the LambdaGlobalProperties attribute +AWSLambda0113 | AWSLambdaCSharpGenerator | Error | The GenerateMain global property is set to true and the OutputType is set to 'exe', but no Lambda Function attributes are used +AWSLambda0114 | AWSLambdaCSharpGenerator | Error | The GenerateMain global property is set to true, but the project already contains a static Main method + ## Release 1.0.0 Rule ID | Category | Severity | Notes --------|----------|----------|------- diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/AnalyzerReleases.Unshipped.md b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/AnalyzerReleases.Unshipped.md index 8c9d1d493..17d4678ce 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/AnalyzerReleases.Unshipped.md +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/AnalyzerReleases.Unshipped.md @@ -1,11 +1,2 @@ ; Unshipped analyzer release ; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md - -### New Rules - -Rule ID | Category | Severity | Notes ---------|----------|----------|------- -AWSLambda0111|AWSLambdaCSharpGenerator|Error|If the GenerateMain global property is set to true but the project OutputType is not set to 'exe' -AWSLambda0112|AWSLambdaCSharpGenerator|Error|An invalid runtime is selected in the LambdaGlobalProperties attribute -AWSLambda0113|AWSLambdaCSharpGenerator|Error|The GenerateMain global property is set to true and the OutputType is set to 'exe', but no Lambda Function attributes are used -AWSLambda0114|AWSLambdaCSharpGenerator|Error|The GenerateMain global property is set to true, but the project already contains a static Main method \ No newline at end of file diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/DiagnosticDescriptors.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/DiagnosticDescriptors.cs index 07bf8ecb2..a511b4b60 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/DiagnosticDescriptors.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/DiagnosticDescriptors.cs @@ -99,7 +99,7 @@ public static class DiagnosticDescriptors public static readonly DiagnosticDescriptor InvalidRuntimeSelection = new DiagnosticDescriptor(id: "AWSLambda0112", title: "Invalid runtime selection", messageFormat: "The runtime selected in the Amazon.Lambda.Annotations.LambdaGlobalPropertiesAttribute is not a supported value. " + - $"The valid values are: {string.Join(", ", Generator._allowdRuntimeValues.ToArray())}", + $"The valid values are: {string.Join(", ", Generator._allowedRuntimeValues.ToArray())}", category: "AWSLambdaCSharpGenerator", DiagnosticSeverity.Error, isEnabledByDefault: true); diff --git a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Generator.cs b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Generator.cs index 74dd4dee0..4ff503042 100644 --- a/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Generator.cs +++ b/Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Generator.cs @@ -1,9 +1,4 @@ -using System; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Text.RegularExpressions; -using Amazon.Lambda.Annotations.SourceGenerator.Diagnostics; +using Amazon.Lambda.Annotations.SourceGenerator.Diagnostics; using Amazon.Lambda.Annotations.SourceGenerator.Extensions; using Amazon.Lambda.Annotations.SourceGenerator.FileIO; using Amazon.Lambda.Annotations.SourceGenerator.Models; @@ -13,11 +8,15 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; namespace Amazon.Lambda.Annotations.SourceGenerator { - using System.Collections.Generic; - [Generator] public class Generator : ISourceGenerator { @@ -25,11 +24,21 @@ public class Generator : ISourceGenerator private readonly IFileManager _fileManager = new FileManager(); private readonly IDirectoryManager _directoryManager = new DirectoryManager(); - internal static readonly List _allowdRuntimeValues = new List(2) + /// + /// Maps .NET TargetFramework values to the corresponding Lambda runtime CloudFormation value + /// + internal static readonly Dictionary _targetFrameworksToRuntimes = new Dictionary(2) + { + { "net6.0", "dotnet6" }, + { "net8.0", "dotnet8" } + }; + + internal static readonly List _allowedRuntimeValues = new List(4) { "dotnet6", "provided.al2", - "provided.al2023" + "provided.al2023", + "dotnet8" }; // Only allow alphanumeric characters @@ -41,10 +50,10 @@ public class Generator : ISourceGenerator public Generator() { #if DEBUG - //if (!Debugger.IsAttached) - //{ - // Debugger.Launch(); - //} + // if (!Debugger.IsAttached) + // { + // Debugger.Launch(); + // } #endif } @@ -63,7 +72,7 @@ public void Execute(GeneratorExecutionContext context) // Check to see if any of the current syntax trees has any error diagnostics. If so // Skip generation. We only want to sync the CloudFormation template if the project // can compile. - foreach(var syntaxTree in context.Compilation.SyntaxTrees) + foreach (var syntaxTree in context.Compilation.SyntaxTrees) { if(syntaxTree.GetDiagnostics().Any(x => x.Severity == DiagnosticSeverity.Error)) { @@ -102,13 +111,23 @@ public void Execute(GeneratorExecutionContext context) var defaultRuntime = "dotnet6"; + // Try to determine the target framework from the source generator context + if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.TargetFramework", out var targetFramework)) + { + if (_targetFrameworksToRuntimes.ContainsKey(targetFramework)) + { + defaultRuntime = _targetFrameworksToRuntimes[targetFramework]; + } + } + + // The runtime specified in the global property has precedence over the one we determined from the TFM (if we did) if (globalPropertiesAttribute != null) { var generateMain = globalPropertiesAttribute.NamedArguments.FirstOrDefault(kvp => kvp.Key == "GenerateMain").Value; var runtimeAttributeValue = globalPropertiesAttribute.NamedArguments.FirstOrDefault(kvp => kvp.Key == "Runtime").Value; var runtime = runtimeAttributeValue.Value == null ? defaultRuntime : runtimeAttributeValue.Value.ToString(); - if (!_allowdRuntimeValues.Contains(runtime)) + if (!_allowedRuntimeValues.Contains(runtime)) { diagnosticReporter.Report(Diagnostic.Create(DiagnosticDescriptors.InvalidRuntimeSelection, Location.None)); return; diff --git a/Libraries/src/Amazon.Lambda.Annotations/LambdaGlobalPropertiesAttribute.cs b/Libraries/src/Amazon.Lambda.Annotations/LambdaGlobalPropertiesAttribute.cs index e32663320..5bdd71ef0 100644 --- a/Libraries/src/Amazon.Lambda.Annotations/LambdaGlobalPropertiesAttribute.cs +++ b/Libraries/src/Amazon.Lambda.Annotations/LambdaGlobalPropertiesAttribute.cs @@ -17,7 +17,7 @@ public class LambdaGlobalPropertiesAttribute : Attribute public bool GenerateMain { get; set; } /// - /// The runtime to set in the generated CloudFormation template. Either 'dotnet6', 'provided.al2' or 'provided.al2023'. + /// The runtime to set in the generated CloudFormation template. Either 'dotnet6', 'provided.al2', 'provided.al2023', or 'dotnet8'. /// public string Runtime { get; set; } } diff --git a/Libraries/src/Amazon.Lambda.Annotations/README.md b/Libraries/src/Amazon.Lambda.Annotations/README.md index 290f6fa98..31dc65772 100644 --- a/Libraries/src/Amazon.Lambda.Annotations/README.md +++ b/Libraries/src/Amazon.Lambda.Annotations/README.md @@ -315,7 +315,7 @@ To auto-generate the `static Main` method, first ensure the `OutputType` in your ``` -Once the output type is set to executable, add the `LambdaGlobalProperties` assembly attribute and set the `GenerateMain` property to true. You can also configure the `Runtime` in the generated CloudFormation template. +Once the output type is set to executable, add the `LambdaGlobalProperties` assembly attribute and set the `GenerateMain` property to true. If `Runtime` is not specified in the global attribute, Lambda Annotations will attempt to determine it from your project file. You can also configure the `Runtime` in the generated CloudFormation template. To allow for multiple Lambda functions in the same executable an Environment Variable is used to determine which handler is executed. When using the `GenerateMain` attribute, ensure you also set the `ANNOTATIONS_HANDLER` environment variable on the deployed Lambda function. diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj index f72142181..b57a3f00c 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj @@ -33,6 +33,15 @@ + + + TestServerlessApp.NET8\%(RecursiveDir)/%(FileName)%(Extension) + Always + + + + + TestExecutableServerlessApp\%(RecursiveDir)/%(FileName)%(Extension) Always @@ -137,6 +146,7 @@ + diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/CSharpSourceGeneratorVerifier.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/CSharpSourceGeneratorVerifier.cs index 960e6fcdc..e8f04629c 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/CSharpSourceGeneratorVerifier.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/CSharpSourceGeneratorVerifier.cs @@ -1,19 +1,21 @@ -using System; -using System.Collections.Immutable; -using Amazon.Lambda.Annotations.APIGateway; +using Amazon.Lambda.Annotations.APIGateway; using Amazon.Lambda.APIGatewayEvents; using Amazon.Lambda.Core; +using Amazon.Lambda.RuntimeSupport; using Amazon.Lambda.Serialization.SystemTextJson; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Testing; +using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Testing.Verifiers; +using Microsoft.CodeAnalysis.Text; using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Immutable; +using System.IO; namespace Amazon.Lambda.Annotations.SourceGenerators.Tests { - using Amazon.Lambda.RuntimeSupport; - /// /// Source: https://github.com/dotnet/roslyn/blob/main/docs/features/source-generators.cookbook.md /// @@ -23,7 +25,10 @@ public static class CSharpSourceGeneratorVerifier public class Test : CSharpSourceGeneratorTest { public enum ReferencesMode {All, NoApiGatewayEvents} - public Test(ReferencesMode referencesMode = ReferencesMode.All) + + public enum TargetFramework { Net60, Net80 } + + public Test(ReferencesMode referencesMode = ReferencesMode.All, TargetFramework targetFramework = TargetFramework.Net60) { if(referencesMode == ReferencesMode.NoApiGatewayEvents) { @@ -51,6 +56,39 @@ public Test(ReferencesMode referencesMode = ReferencesMode.All) .AddMetadataReference(projectId, MetadataReference.CreateFromFile(typeof(LambdaBootstrapBuilder).Assembly.Location)); }); } + + // Set up the target framework moniker and reference assemblies + if (targetFramework == TargetFramework.Net60) + { + SolutionTransforms.Add((solution, projectId) => + { + return solution.AddAnalyzerConfigDocument( + DocumentId.CreateNewId(projectId), + "TargetFrameworkConfig.editorconfig", + SourceText.From(""" + is_global = true + build_property.TargetFramework = net6.0 + """), + filePath: "/TargetFrameworkConfig.editorconfig"); + }); + ReferenceAssemblies = ReferenceAssemblies.Net.Net60; + } + else if (targetFramework == TargetFramework.Net80) + { + SolutionTransforms.Add((solution, projectId) => + { + return solution.AddAnalyzerConfigDocument( + DocumentId.CreateNewId(projectId), + "TargetFrameworkConfig.editorconfig", + SourceText.From(""" + is_global = true + build_property.TargetFramework = net8.0 + """), + filePath: "/TargetFrameworkConfig.editorconfig"); + }); + // There isn't a static .NET 8 yet + ReferenceAssemblies = new ReferenceAssemblies("net8.0", new PackageIdentity("Microsoft.NETCore.App.Ref", "8.0.0"), Path.Combine("ref", "net8.0")); + } } protected override CompilationOptions CreateCompilationOptions() diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_ToUpper_Generated_NET8.g.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_ToUpper_Generated_NET8.g.cs new file mode 100644 index 000000000..551e0b626 --- /dev/null +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Functions_ToUpper_Generated_NET8.g.cs @@ -0,0 +1,45 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using System.IO; +using Amazon.Lambda.Core; + +namespace TestServerlessApp.NET8 +{ + public class Functions_ToUpper_Generated + { + private readonly Functions functions; + private readonly Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer serializer; + + public Functions_ToUpper_Generated() + { + SetExecutionEnvironment(); + functions = new Functions(); + serializer = new Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer(); + } + + public string ToUpper(string text) + { + return functions.ToUpper(text); + } + + private static void SetExecutionEnvironment() + { + const string envName = "AWS_EXECUTION_ENV"; + + var envValue = new StringBuilder(); + + // If there is an existing execution environment variable add the annotations package as a suffix. + if(!string.IsNullOrEmpty(Environment.GetEnvironmentVariable(envName))) + { + envValue.Append($"{Environment.GetEnvironmentVariable(envName)}_"); + } + + envValue.Append("amazon-lambda-annotations_1.1.0.0"); + + Environment.SetEnvironmentVariable(envName, envValue.ToString()); + } + } +} \ No newline at end of file diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/net8.template b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/net8.template new file mode 100644 index 000000000..70ce779a4 --- /dev/null +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/net8.template @@ -0,0 +1,24 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Transform": "AWS::Serverless-2016-10-31", + "Description": "This template is partially managed by Amazon.Lambda.Annotations (v1.0.0.0).", + "Resources": { + "TestServerlessAppNET8FunctionsToUpperGenerated": { + "Type": "AWS::Serverless::Function", + "Metadata": { + "Tool": "Amazon.Lambda.Annotations" + }, + "Properties": { + "Runtime": "dotnet8", + "CodeUri": ".", + "MemorySize": 256, + "Timeout": 30, + "Policies": [ + "AWSLambdaBasicExecutionRole" + ], + "PackageType": "Zip", + "Handler": "TestProject::TestServerlessApp.NET8.Functions_ToUpper_Generated::ToUpper" + } + } + } +} \ No newline at end of file diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs index 6361970c5..a8c04be0d 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs @@ -49,8 +49,7 @@ public async Task Greeter() new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("Greeter_SayHello_Generated.g.cs", expectedSayHelloGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("Greeter_SayHelloAsync_Generated.g.cs", expectedSayHelloAsyncGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent) - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }.RunAsync(); @@ -80,8 +79,7 @@ public async Task TestExecutableOutputWithNoAnnotations() .WithMessage("Your project is configured to output an executable and generate a static Main method, but you have not configured any methods with the 'LambdaFunction' attribute"), DiagnosticResult.CompilerError("CS5001") .WithMessage("Program does not contain a static 'Main' method suitable for an entry point"), - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }.RunAsync(); } @@ -113,8 +111,7 @@ public async Task GeneratorDoesNotRunDueToCompileError() { // Now AWS Lambda Annotations INFO diagnostics were emited showing again the generator didn't run. new DiagnosticResult("CS1513", DiagnosticSeverity.Error).WithSpan("NonCompilableCodeFile.cs", 22, 2, 22, 2) - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }.RunAsync(); } @@ -196,8 +193,7 @@ public async Task SimpleCalculator() new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("SimpleCalculator_Random_Generated.g.cs", expectedRandomGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("SimpleCalculator_Randoms_Generated.g.cs", expectedRandomsGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent) - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }.RunAsync(); @@ -241,8 +237,7 @@ public async Task ComplexCalculator() new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("ComplexCalculator_Add_Generated.g.cs", expectedAddGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("ComplexCalculator_Subtract_Generated.g.cs", expectedSubtractGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent) - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }.RunAsync(); @@ -269,9 +264,8 @@ public async Task TestInvalidGlobalRuntime_ShouldError() }, ExpectedDiagnostics = { - new DiagnosticResult("AWSLambda0112", DiagnosticSeverity.Error).WithMessage("The runtime selected in the Amazon.Lambda.Annotations.LambdaGlobalPropertiesAttribute is not a supported value. The valid values are: dotnet6, provided.al2, provided.al2023"), - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + new DiagnosticResult("AWSLambda0112", DiagnosticSeverity.Error).WithMessage("The runtime selected in the Amazon.Lambda.Annotations.LambdaGlobalPropertiesAttribute is not a supported value. The valid values are: dotnet6, provided.al2, provided.al2023, dotnet8"), + } } }; @@ -315,8 +309,7 @@ public async Task VerifyFunctionInSubNamespace() { new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("Functions_ToUpper_Generated.g.cs", expectedSubNamespaceGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent), - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }.RunAsync(); @@ -363,8 +356,7 @@ public async Task VerifyExecutableAssemblyWithZipAndHandler() { new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("FunctionsZipOutput_ToLower_Generated.g.cs", expectedSubNamespaceGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent), - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }; @@ -423,8 +415,7 @@ public async Task VerifyExecutableAssembly() { new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("Functions_ToUpper_Generated.g.cs", expectedSubNamespaceGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent), - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }; @@ -480,8 +471,7 @@ public async Task VerifyExecutableAssemblyWithParameterlessConstructor() { new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("ParameterlessMethods_NoParameter_Generated.g.cs", expectedSubNamespaceGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent), - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }; @@ -537,8 +527,7 @@ public async Task VerifyExecutableAssemblyWithParameterlessConstructorAndRespons { new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("ParameterlessMethodWithResponse_NoParameterWithResponse_Generated.g.cs", expectedSubNamespaceGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent), - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }; @@ -588,8 +577,7 @@ public async Task VerifyExecutableAssembly_WithNullAttributeValues_ShouldComplet { new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("Functions_ToUpper_Generated.g.cs", expectedSubNamespaceGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent), - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }.RunAsync(); @@ -643,8 +631,7 @@ public async Task VerifyExecutableAssemblyWithMultipleHandler() new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("Greeter_SayHello_Generated.g.cs", expectedSayHello), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("Greeter_SayHelloAsync_Generated.g.cs", expectedSayHelloAsync), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent), - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }; @@ -708,8 +695,7 @@ public async Task VerifySourceGeneratorSerializerWithHttpResultsBody() DiagnosticResult.CompilerError("CS0534").WithSpan($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}SourceGenerationSerializationExample.cs", 28, 26, 28, 54).WithArguments("TestExecutableServerlessApp.HttpApiJsonSerializerContext", "System.Text.Json.Serialization.JsonSerializerContext.GeneratedSerializerOptions.get"), DiagnosticResult.CompilerError("CS0534").WithSpan($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}SourceGenerationSerializationExample.cs", 28, 26, 28, 54).WithArguments("TestExecutableServerlessApp.HttpApiJsonSerializerContext", "System.Text.Json.Serialization.JsonSerializerContext.GetTypeInfo(System.Type)"), DiagnosticResult.CompilerError("CS7036").WithSpan($"TestExecutableServerlessApp{Path.DirectorySeparatorChar}SourceGenerationSerializationExample.cs", 28, 26, 28, 54).WithArguments("options", "System.Text.Json.Serialization.JsonSerializerContext.JsonSerializerContext(System.Text.Json.JsonSerializerOptions?)"), - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }; @@ -758,8 +744,7 @@ public async Task VerifyFunctionReturnVoid() { new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("VoidExample_VoidReturn_Generated.g.cs", expectedSubNamespaceGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent) - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }.RunAsync(); @@ -797,8 +782,7 @@ public async Task VerifyNoErrorWithIntrinsicInTemplate() { new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("IntrinsicExample_HasIntrinsic_Generated.g.cs", expectedSubNamespaceGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent) - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }.RunAsync(); @@ -835,8 +819,7 @@ public async Task VerifyFunctionReturnTask() { new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("TaskExample_TaskReturn_Generated.g.cs", expectedSubNamespaceGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent) - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }.RunAsync(); @@ -880,8 +863,7 @@ public async Task VerifyFunctionDynamic() new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("DynamicExample_DynamicReturn_Generated.g.cs", expectedSubNamespaceGenerated_DynamicReturn), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("DynamicExample_DynamicInput_Generated.g.cs", expectedSubNamespaceGenerated_DynamicInput) - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } }.RunAsync(); @@ -959,10 +941,8 @@ public async Task CustomizeResponses() new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("CustomizeResponseExamples_NotFoundResponseWithHeaderV1Async_Generated.g.cs", expectedNotFoundResponseWithHeaderV1AsyncGenerated), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent) - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } - }.RunAsync(); var actualTemplateContent = await File.ReadAllTextAsync(Path.Combine("TestServerlessApp", "serverless.template")); @@ -991,10 +971,8 @@ public async Task InvalidReturnTypeIHttpResult() ExpectedDiagnostics = { DiagnosticResult.CompilerError("AWSLambda0105").WithSpan($"TestServerlessApp{Path.DirectorySeparatorChar}CustomizeResponseWithErrors.cs", 14, 9, 21, 10).WithArguments("Error") - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 + } } - }.RunAsync(); } @@ -1020,9 +998,7 @@ public async Task MissingResourePathMapping() DiagnosticResult.CompilerError("AWSLambda0107").WithSpan($"TestServerlessApp{Path.DirectorySeparatorChar}MissingResourePathMapping.cs", 15, 9, 20, 10) .WithMessage("Route template /add/{x}/{y} is invalid. Missing x parameters in method definition.") }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 } - }.RunAsync(); } @@ -1057,9 +1033,8 @@ public async Task VerifyApiFunctionUsingNullableParameters() { new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("NullableReferenceTypeExample_NullableHeaderHttpApi_Generated.g.cs", expectedCSharpContent), new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestServerlessApp{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent) - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60, - }, + } + }, }; await test.RunAsync(); @@ -1092,7 +1067,6 @@ public async Task VerifyNoApiGatewayEventsReference() .WithMessage("Your project has a missing required package dependency. Please add a reference to the following package: Amazon.Lambda.APIGatewayEvents.") .WithSpan($"TestServerlessApp{Path.DirectorySeparatorChar}FromScratch{Path.DirectorySeparatorChar}NoApiGatewayEventsReference.cs", 9, 9, 14, 10), }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60, }, }; @@ -1120,7 +1094,6 @@ public async Task VerifyNoSerializerAttributeReference() new DiagnosticResult("AWSLambda0108", DiagnosticSeverity.Error) .WithSpan($"TestServerlessApp{Path.DirectorySeparatorChar}FromScratch{Path.DirectorySeparatorChar}NoSerializerAttributeReference.cs", 9, 9, 13, 10), }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60, }, }; @@ -1149,7 +1122,6 @@ public async Task ComplexQueryParameters_AreNotSupported() DiagnosticResult.CompilerError("AWSLambda0109").WithSpan($"TestServerlessApp{Path.DirectorySeparatorChar}ComplexQueryParameter.cs", 11, 9, 16, 10) .WithMessage("Unsupported query parameter 'person' of type 'TestServerlessApp.Person' encountered. Only primitive .NET types and their corresponding enumerable can be used as query parameters.") }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 } }.RunAsync(); @@ -1183,12 +1155,48 @@ public async Task InvalidParameterAttributeNames_ThrowsDiagnosticErrors() DiagnosticResult.CompilerError("AWSLambda0110").WithSpan($"TestServerlessApp{Path.DirectorySeparatorChar}InvalidParameterAttributeNames.cs", 26, 9, 31, 10) .WithMessage("Invalid parameter attribute name 'first@name' for method parameter 'firstName' encountered. Valid values can only contain uppercase and lowercase alphanumeric characters, periods (.), hyphens (-), underscores (_) and dollar signs ($).") }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60 } }.RunAsync(); } + /// + /// Verifies that we set 'dotnet8' in the CFN Lambda runtime for a project targeting .NET 8 + /// + [Fact] + public async Task ToUpper_Net8() + { + var expectedFunctionContent = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "Functions_ToUpper_Generated_NET8.g.cs"))).ToEnvironmentLineEndings(); + var expectedTemplateContent = (await File.ReadAllTextAsync(Path.Combine("Snapshots", "ServerlessTemplates", "net8.template"))).ToEnvironmentLineEndings(); + + await new VerifyCS.Test(targetFramework: VerifyCS.Test.TargetFramework.Net80) + { + TestState = + { + Sources = + { + (Path.Combine("TestServerlessApp.NET8", "Functions.cs"), await File.ReadAllTextAsync(Path.Combine("TestServerlessApp.NET8", "Functions.cs"))), + (Path.Combine("TestServerlessApp.NET8", "AssemblyAttributes.cs"), await File.ReadAllTextAsync(Path.Combine("TestServerlessApp.NET8", "AssemblyAttributes.cs"))), + + }, + GeneratedSources = + { + (typeof(SourceGenerator.Generator), + "Functions_ToUpper_Generated.g.cs", + SourceText.From(expectedFunctionContent, Encoding.UTF8, SourceHashAlgorithm.Sha256)) + }, + ExpectedDiagnostics = + { + new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments("Functions_ToUpper_Generated.g.cs", expectedFunctionContent), + new DiagnosticResult("AWSLambda0103", DiagnosticSeverity.Info).WithArguments($"TestServerlessApp.NET8{Path.DirectorySeparatorChar}serverless.template", expectedTemplateContent) + } + } + }.RunAsync(); + + var actualTemplateContent = await File.ReadAllTextAsync(Path.Combine("TestServerlessApp.NET8", "serverless.template")); + Assert.Equal(expectedTemplateContent, actualTemplateContent); + } + public void Dispose() { File.Delete(Path.Combine("TestServerlessApp", "serverless.template")); diff --git a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/ProjectFileHandlerTests.cs b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/ProjectFileHandlerTests.cs index f05c8f798..f0b33ee84 100644 --- a/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/ProjectFileHandlerTests.cs +++ b/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/ProjectFileHandlerTests.cs @@ -1,6 +1,7 @@ using Amazon.Lambda.Annotations.SourceGenerator; using Amazon.Lambda.Annotations.SourceGenerator.FileIO; using Moq; +using System.IO; using Xunit; namespace Amazon.Lambda.Annotations.SourceGenerators.Tests.WriterTests diff --git a/Libraries/test/TestServerlessApp.NET8/AssemblyAttributes.cs b/Libraries/test/TestServerlessApp.NET8/AssemblyAttributes.cs new file mode 100644 index 000000000..955e187fc --- /dev/null +++ b/Libraries/test/TestServerlessApp.NET8/AssemblyAttributes.cs @@ -0,0 +1,3 @@ +using Amazon.Lambda.Core; + +[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))] \ No newline at end of file diff --git a/Libraries/test/TestServerlessApp.NET8/Functions.cs b/Libraries/test/TestServerlessApp.NET8/Functions.cs new file mode 100644 index 000000000..cf322af21 --- /dev/null +++ b/Libraries/test/TestServerlessApp.NET8/Functions.cs @@ -0,0 +1,15 @@ +using Amazon.Lambda.Annotations; + +namespace TestServerlessApp.NET8; + +/// +/// Sample Lambda functions +/// +public class Functions +{ + [LambdaFunction] + public string ToUpper(string text) + { + return text.ToUpper(); + } +} \ No newline at end of file diff --git a/Libraries/test/TestServerlessApp.NET8/TestServerlessApp.NET8.csproj b/Libraries/test/TestServerlessApp.NET8/TestServerlessApp.NET8.csproj new file mode 100644 index 000000000..be36f93c9 --- /dev/null +++ b/Libraries/test/TestServerlessApp.NET8/TestServerlessApp.NET8.csproj @@ -0,0 +1,29 @@ + + + Library + net8.0 + enable + enable + true + Lambda + + true + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/Libraries/test/TestServerlessApp.NET8/aws-lambda-tools-defaults.json b/Libraries/test/TestServerlessApp.NET8/aws-lambda-tools-defaults.json new file mode 100644 index 000000000..9be29a0d9 --- /dev/null +++ b/Libraries/test/TestServerlessApp.NET8/aws-lambda-tools-defaults.json @@ -0,0 +1,15 @@ +{ + "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": "default", + "region": "us-east-1", + "configuration": "Release", + "s3-prefix": "TestServerlessApp.NET8/", + "template": "serverless.template", + "template-parameters": "", + "docker-host-build-output-dir": "./bin/Release/lambda-publish" +} \ No newline at end of file diff --git a/Libraries/test/TestServerlessApp.NET8/serverless.template b/Libraries/test/TestServerlessApp.NET8/serverless.template new file mode 100644 index 000000000..fd66b9b4a --- /dev/null +++ b/Libraries/test/TestServerlessApp.NET8/serverless.template @@ -0,0 +1,24 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Transform": "AWS::Serverless-2016-10-31", + "Description": "This template is partially managed by Amazon.Lambda.Annotations (v1.0.0.0).", + "Resources": { + "TestServerlessAppNET8FunctionsToUpperGenerated": { + "Type": "AWS::Serverless::Function", + "Metadata": { + "Tool": "Amazon.Lambda.Annotations" + }, + "Properties": { + "Runtime": "dotnet8", + "CodeUri": ".", + "MemorySize": 256, + "Timeout": 30, + "Policies": [ + "AWSLambdaBasicExecutionRole" + ], + "PackageType": "Zip", + "Handler": "TestServerlessApp.NET8::TestServerlessApp.NET8.Functions_ToUpper_Generated::ToUpper" + } + } + } +} \ No newline at end of file