aws-lambda-dotnet
aws-lambda-dotnet copied to clipboard
Parameter of type Amazon.Lambda.SQSEvents.SQSEvent passing is not supported
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
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
Might be related to https://github.com/aws/aws-lambda-dotnet/pull/1203.
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).
@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?
@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.
@Sparafusile In this example is Credentials supposed to come from the response body?
@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.