question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Amazon.Lambda.TestTool-6.0 needs to work with dot net 6 top-level statements

See original GitHub issue

With 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:open
  • Created 2 years ago
  • Reactions:25
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
ashishdhingracommented, Mar 2, 2022

Needs review with the team.

3reactions
avalara-stephen-hickeycommented, Jul 29, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing the .NET 6 runtime for AWS Lambda
NET 6 runtime to build AWS Lambda functions. ... With top-level statements, the Main() method has been generated by the compiler.
Read more >
Updating an AWS Lambda app to .NET 6.0 - Marcus Turewicz
The following items need to be updated in the CloudFormation template: Runtime to dotnet6; If using Top Level Statements (see below), set the ......
Read more >
Baseline Performance for AWS Lambda .NET using Top- ...
NET 6 introduced top-level statements, which simplify the entry point ... this Lambda function has 20% to 100% longer cold start durations.
Read more >
AWS Lambda backs .NET 6
NET 6 Lambda runtime supports writing Lambda functions using C# 9 top-level statements, which allow developers to delete much of the initial ...
Read more >
Cannot start lambda with Mock Lambda Test Tool
I came to this question having the very same issue. After installing AWS Toolkit I found that the lambda test tool was not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found