Amazon.Lambda.TestTool-6.0 needs to work with dot net 6 top-level statements
See original GitHub issueWith dot net 6 runtime support for lambda, we want to write lambda function handler as top level statement as described in the document https://aws.amazon.com/blogs/compute/introducing-the-net-6-runtime-for-aws-lambda/
To use Amazon.Lambda.TestTool-6.0 to test lambda written as top level statement, we need the test tool to support that.
Example code for lambda with top level statement for a project called LambdaProject
using Amazon.Lambda.Core;
using Amazon.Lambda.RuntimeSupport;
using Amazon.Lambda.Serialization.SystemTextJson;
using Amazon.Lambda.S3Events;
using Amazon.S3;
// Code outside of the handler will be executed during Lambda initialization
var s3Client = new AmazonS3Client();
// The function handler that will be called for each Lambda event
var handler = async (S3Event evnt, ILambdaContext context) =>
{
foreach(var record in evnt.Records)
{
using var response = await s3Client.GetObjectAsync(record.S3.Bucket.Name, record.S3.Object.Key);
using var reader = new StreamReader(response.ResponseStream);
// Run business logic on the text contexts of the S3 object
}
};
// Build the Lambda runtime client passing in the handler to call for each
// event and the JSON serializer to use for translating Lambda JSON documents
// to .NET types.
await LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
.Build()
.RunAsync();
Now the .NET Lambda function handler string is LambdaProject
Currently Amazon.Lambda.TestTool-6.0 does not support this as we can see here
https://github.com/aws/aws-lambda-dotnet/blob/0f7b6353466c398487a72264ab241ec04a9c4567/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool/Runtime/LocalLambdaRuntime.cs#L96
Code is still trying to find function handler in <assembly>::<type-name>::<method> format.
- 👋 I may be able to implement this feature request
- ⚠️ This feature might incur a breaking change
This is a 🚀 Feature Request
Issue Analytics
- State:
- Created 2 years ago
- Reactions:25
- Comments:11 (2 by maintainers)

Top Related StackOverflow Question
Needs review with the team.
This seems like a required feature to be able to use top level statements.
Which is sad, because the set up code for function based lambdas is ugly when you need async configuration. The sample app is calling async methods in initialization code without awaiting the result, which is a solved problem with top level statements.