Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter of type Amazon.Lambda.SQSEvents.SQSEvent passing is not supported #1245

Closed
Sparafusile opened this issue Jul 14, 2022 · 8 comments
Closed
Assignees
Labels
bug This issue is a bug. module/lambda-client-lib p2 This is a standard priority issue

Comments

@Sparafusile
Copy link

Describe the bug

I am unable to create a function with the following signature:

[LambdaFunction, HttpApi( LambdaHttpMethod.Get, "/sqsevent" )]
public async Task SqsEvent( SQSEvent evnt, ILambdaContext context )

Expected Behavior

I would like to be able to write a endpoint that accepts a SQS message.

Current Behavior

log.txt

Severity	Code	Description	Project	File	Line	Suppression State
Error	AWSLambda0001	This is a bug. Please run the build with detailed verbosity (dotnet build --verbosity detailed) and file a bug at https://github.com/aws/aws-lambda-dotnet with the build output and stack trace evnt parameter of type Amazon.Lambda.SQSEvents.SQSEvent passing is not supported.   at Amazon.Lambda.Annotations.SourceGenerator.Templates.LambdaFunctionTemplate.TransformText()	API	C:\Users\foobar\API\CSC	1

Reproduction Steps

using Amazon.Lambda.Core;
using Amazon.Lambda.SQSEvents;
using Amazon.Lambda.Annotations;

[assembly: LambdaSerializer( typeof( Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer ) )]

namespace API
{
    public class Functions
    {
        public Functions()
        {
        }

        [LambdaFunction, HttpApi( LambdaHttpMethod.Get, "/sqsevent" )]
        public async Task SqsEvent( SQSEvent evnt, ILambdaContext context )
        {
        }
    }
}

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

Amazon.Lambda.Annotations - 0.5.0 preview
Amazon.Lambda.GatewayEvents - 2.4.1
Amazon.Lambda.Core - 2.1.0
Amazon.Lambda.S3Events - 2.0.1
Amazon.Lambda.Serialization.SystemTextJson - 2.3.0
Amazon.Lambda.SQSEvents - 2.1.0
AWSSDK.DynamoDBv2 - 3.7.3.53

Targeted .NET Platform

.NET 6

Operating System and version

Windows 10

@Sparafusile Sparafusile added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 14, 2022
@ashishdhingra
Copy link
Contributor

Might be related to #1203.

@ashishdhingra ashishdhingra removed the needs-triage This issue or PR still needs to be triaged. label Jul 22, 2022
@Sparafusile
Copy link
Author

If it's any help, the compiler succeeds if I change the function definition to this:

[LambdaFunction]
public bool SqsEvent( SQSEvent evnt, ILambdaContext context )
{
    return true;
}

or this:

[LambdaFunction]
public async Task<bool> SqsEvent( SQSEvent evnt, ILambdaContext context )
{
    return true;
}

What I needed to do is remove the HttpApiAttribute (which defeats the purpose of the project) and make the method return a value (even if it's useless).

@normj
Copy link
Member

normj commented Aug 26, 2022

@Sparafusile I'm trying to understand what you want to accomplish. The HttpApi attribute is used for exposing the Lambda function as a API Gateway rest endpoint. Where is the SQS event supposed to come from in your scenario with HttpApi?

We would like to add additional attributes to the library that handle subscribing an SQS queue as the event source of the Lambda function. Is that the feature you are looking for?

@Sparafusile
Copy link
Author

@normj My specific use case is to consolidate a list of Lambda function which are each a separate project in my Visual Studio solution. My goal is to make it easier to deploy all lambda functions at once. Not all my lambda functions do have an API endpoint, but some do. This post above was simply the first function I tried.

A better example would probably be the custom identity provider I'm using for a SFTP server running in AWS Transfer:

[HttpApi( ... )]
[LambdaFunction( ... )]
public Response FunctionHandler( Credentials c, ... )
{
    // ...
}

public class Credentials
{
    ...
}

The API endpoint is required in this case, but it will throw an error because it doesn't know what to do with the Credientials parameter (and neither do I - AWS transfer documentation doesn't seem to specify how these are provided to the lambda). Using [FromBody] or [FromQuery] on the Credentials parameter does not solve the compile time issue that I listed in my initial post.

@normj
Copy link
Member

normj commented Oct 14, 2022

@Sparafusile In this example is Credentials supposed to come from the response body?

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. no-autoclose labels Oct 14, 2022
@Sparafusile
Copy link
Author

Sparafusile commented Oct 14, 2022

@normj I'm not entirely sure. Here is the definition of the entry point for the stand-alone lambda project that I have in production:

public Response FunctionHandler( Credentials c, ILambdaContext context )
{
}
public class Credentials
{
    public string ServerID { get; set; }
    public string Username { get; set; }
    public string Password { get; set; }
}

Here is a link to the documentation I used: https://docs.aws.amazon.com/transfer/latest/userguide/custom-identity-provider-users.html#authentication-api-gateway

Looking at the yml that is used to set this up, it looks like the credentials come from the query parameters.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Aug 22, 2023
@ashishdhingra ashishdhingra added p2 This is a standard priority issue needs-review labels Aug 28, 2023
@normj
Copy link
Member

normj commented Sep 9, 2024

Closing because this is not a scenario that Lambda or Annotations supports having a single Lambda function responded to both an HTTP and SQS because the serialization would have no idea what type of event is coming in to serialize.

@normj normj closed this as completed Sep 9, 2024
Copy link
Contributor

github-actions bot commented Sep 9, 2024

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. module/lambda-client-lib p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

4 participants