Aws-cdk: Unable to add SQS queue as an event source in C#

Created on 30 May 2019  路  6Comments  路  Source: aws/aws-cdk

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:
```c#
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.TryDeserializeTResponse
at Amazon.JSII.Runtime.Services.Client.ReceiveResponseTResponse
at Amazon.JSII.Runtime.Services.Client.TryDeserializeTResponse
at Amazon.JSII.Runtime.Services.Client.ReceiveResponseTResponse
at Amazon.JSII.Runtime.Deputy.DeputyBase.g__GetResult|18_0T
at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeMethodCoreT
at Amazon.CDK.AWS.Lambda.EventSources.SqsEventSource.Bind(IIFunction target)'
at Amazon.JSII.Runtime.Services.Client.TryDeserializeTResponse
at Amazon.JSII.Runtime.Services.Client.ReceiveResponseTResponse
at Amazon.JSII.Runtime.Services.Client.TryDeserializeTResponse
at Amazon.JSII.Runtime.Services.Client.ReceiveResponseTResponse
at Amazon.JSII.Runtime.Deputy.DeputyBase.g__GetResult|18_0T
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
bug p1

Most helpful comment

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

All 6 comments

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

Any updates to this issue? It is still failing in the version 1.9.0-preview, and this is a valuable feature for Lambda functions that I would like to use.

Thanks!

The same problem applies to
```c#
someQueue.GrantConsumeMessages(someRole)

This on the other hand works
```c#
someQueue.(someRole, "sqs:SendMessage", "sqs:GetQueueAttributes", "sqs:GetQueueUrl")

Get the same error when running
```c#
someQueue.GrantConsumeMessages(someRole)

This on the other hand works
```c#
someQueue.Grant(someRole,
                "sqs:ChangeMessageVisibility",
                "sqs:DeleteMessage",
                "sqs:ReceiveMessage",
                "sqs:GetQueueAttributes",
                "sqs:GetQueueUrl"
            );

Workaround:
c# someFunction.AddEventSourceMapping("SomeId", new EventSourceMappingProps { BatchSize = 10, Enabled = true, EventSourceArn = someQueue.QueueArn, Target = someFunction });

This may be fixed in the next CDK release.

This should be fixed in the current release!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nzspambot picture nzspambot  路  3Comments

abelmokadem picture abelmokadem  路  3Comments

cybergoof picture cybergoof  路  3Comments

ababra picture ababra  路  3Comments

kawamoto picture kawamoto  路  3Comments