aws-lambda-dotnet
aws-lambda-dotnet copied to clipboard
Decorating async Task function with [LambdaFunction] generates compile error
Describe the bug
The generated code is awaiting the Task and attempting to return the Task, but because the original method is async, the original method is really a void, so it cannot be returned.
Expected Behavior
No compile errors.
Current Behavior
Receive Compile Error:
Severity Code Description Project File Line
Error CS1997 Since 'Functions_SqsMessageHandler_Generated.SqsMessageHandler(SQSEvent.SQSMessage, ILambdaContext)' is an async method that returns 'Task', a return keyword must not be followed by an object expression. Did you intend to return 'Task<T>'? ServerlessWithSqs C:\Users\17034\source\repos\ServerlessWithSqs\ServerlessWithSqs\Amazon.Lambda.Annotations.SourceGenerator\Amazon.Lambda.Annotations.SourceGenerator.Generator\Functions_SqsMessageHandler_Generated.g.cs 35
Reproduction Steps
Steps to reproduce:
- Create a new serverless project
- Choose the Annotations blueprint
- In Function.cs add the below code:
[LambdaFunction]
public async Task SqsMessageHandler(SQSEvent.SQSMessage sqsMessage, ILambdaContext context)
{
await Task.Delay(1);
}
- Build the project
Possible Solution
remove the return? return without the await?
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
<PackageReference Include="Amazon.Lambda.Annotations" Version="0.5.0-preview" />
Targeted .NET Platform
.NET 6
Operating System and version
Windows 11, AmazonLinux
Reproducible. Unsure if the Annotations Framework could be used with simple Lambda functions. The Readme at https://github.com/aws/aws-lambda-dotnet/tree/master/Libraries/src/Amazon.Lambda.Annotations specifies use of HttpApi or RestApi for Annotations serverless application. Needs review with the team.
@hounddog22030 Looks like the linked PR https://github.com/aws/aws-lambda-dotnet/pull/1257 is merged. Could you please test your scenario and confirm if it works now?
Thanks, Ashish
This issue has not received a response in 5 days. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.