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.

Unable to add SQS queue as an event source in C#

See original GitHub issue

Describe the bug Adding an SQS queue as an event source to a lambda function throws an exception with message “Parameter count mismatch.” in C#.

To Reproduce

This example adds the queue as an event source after the function object is created, but I receive the same error if I try to add the queue as an event source at the time of function creation via the “Events” property.

Code:

var app = new App(new AppProps());

var stack = new Stack(app, "MyTestStack", new StackProps());

var function = new Function(stack, "MyTestLambdaFunction", new FunctionProps
{
    Runtime = Runtime.DotNetCore21,
    Handler = "MyTestAssembly::MyTestClass::Handler",
    Code = new CfnParametersCode(new CfnParametersCodeProps
    {
        BucketNameParam = new CfnParameter(stack, "BucketNameParameter", new CfnParameterProps{Type="String"}),
        ObjectKeyParam = new CfnParameter(stack, "ObjectKeyParameter", new CfnParameterProps{Type="String"})
    }),
    FunctionName = "MyTestFunction"
}); 

var queue = new Queue(stack, "MyTestQueue", new QueueProps
{
    QueueName = "MyTestQueue"
});
            
function.AddEventSource(new SqsEventSource(queue, new SqsEventSourceProps()));

Stacktrace:

An unhandled exception of type 'Amazon.JSII.Runtime.JsiiException' occurred in Amazon.JSII.Runtime.dll: 'Amazon.JSII.Runtime.JsiiException: Amazon.JSII.Runtime.JsiiException: System.Reflection.TargetParameterCountException: Parameter count mismatch.
   at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Amazon.JSII.Runtime.CallbackExtensions.InvokeMethod(InvokeRequest request, IReferenceMap referenceMap)
   at Amazon.JSII.Runtime.CallbackExtensions.InvokeCallback(Callback callback, IReferenceMap referenceMap, IFrameworkToJsiiConverter converter, String& error)
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<InvokeMethodCore>g__GetResult|18_0[T](<>c__DisplayClass18_0`1& )
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeMethodCore[T](JsiiMethodAttribute methodAttribute, Object[] arguments, Func`3 beginFunc, Func`3 invokeFunc)
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<InvokeMethodCore>g__GetResult|18_0[T](<>c__DisplayClass18_0`1& )
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeMethodCore[T](JsiiMethodAttribute methodAttribute, Object[] arguments, Func`3 beginFunc, Func`3 invokeFunc)
   at Amazon.CDK.AWS.Lambda.EventSources.SqsEventSource.Bind(IIFunction target)'
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<InvokeMethodCore>g__GetResult|18_0[T](<>c__DisplayClass18_0`1& )
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeMethodCore[T](JsiiMethodAttribute methodAttribute, Object[] arguments, Func`3 beginFunc, Func`3 invokeFunc)
   at Amazon.CDK.AWS.Lambda.FunctionBase.AddEventSource(IIEventSource source)

Expected behavior The SQS queue is added as an event source to the lambda function.

Version:

  • OSX
  • C#
  • 0.33

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
carlosrfernandezcommented, Jul 23, 2019

Any updates on this? It happens on the latest preview as well

1reaction
sveinhelgecommented, Sep 27, 2019

Workaround:

someFunction.AddEventSourceMapping("SomeId", new EventSourceMappingProps
            {
                BatchSize = 10,
                Enabled = true,
                EventSourceArn = someQueue.QueueArn,
                Target = someFunction
            });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to add SQS queue as an event source in C# #2692
Adding an SQS queue as an event source to a lambda function throws an exception with message "Parameter count mismatch." in C#. To...
Read more >
Tutorial - Use SQS as an Event Source for Lambda
In this tutorial, learn how to use Amazon SQS as an Event Source for Lambda. Lambda allows your code to be triggered using...
Read more >
SQS Event Source not being created on AWS SAM Lambda ...
Ref subnetIds Events: BootstrapFunctionSQSEvent: Type: SQS Properties: Queue: !GetAtt TaskQueue.Arn BatchSize: 1 Enabled: true.
Read more >
AWS Serverless Failed-Event Destinations - W3Schools
You can do it for both asynchronous and streaming event sources. You can use SNS topic, SQS Queue, or another Lambda function as...
Read more >
Why isn't my Lambda function with an Amazon SQS event ...
Your browser can't play this video. ... Why isn't my Lambda function with an Amazon SQS event source scaling optimally?
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