aws-lambda-dotnet icon indicating copy to clipboard operation
aws-lambda-dotnet copied to clipboard

Decorating async Task function with [LambdaFunction] generates compile error

Open hounddog22030 opened this issue 3 years ago • 1 comments

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:

  1. Create a new serverless project
  2. Choose the Annotations blueprint
  3. In Function.cs add the below code:
    [LambdaFunction]
    public async Task SqsMessageHandler(SQSEvent.SQSMessage sqsMessage, ILambdaContext context)
    {
        await Task.Delay(1);
    }

  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

hounddog22030 avatar Jun 11 '22 15:06 hounddog22030

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.

ashishdhingra avatar Jun 13 '22 15:06 ashishdhingra

@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

ashishdhingra avatar Nov 01 '22 22:11 ashishdhingra

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.

github-actions[bot] avatar Nov 07 '22 00:11 github-actions[bot]