Search code examples
amazon-sqsaws-cdk

How to set external SQS Queue reference for aws-eventbridge-sqs CDK construct?


I am using AWS Solutions Constructs library to define an EventBridge Rule for linking an EventBus with SQS queue, i.e.: https://docs.aws.amazon.com/solutions/latest/constructs/aws-eventbridge-sqs.html

As the documentation states, it is possible to either define parameters for SQS Queue that would be created by the CDK Construct or a reference of an existing queue can be passed over. I am trying to use the later approach with Python CDK App and use that parameter:

Name                Type
existingQueueObj?   sqs.Queue

The issue is, I have access just to a queue ARN that I can use to create an IQueue interface using sqs.Queue.from_queue_arn CDK function which does not comply with the requested type here so I am getting following error:

TypeError: type of argument existing_queue_obj must be one of (aws_cdk.aws_sqs.Queue, NoneType); got aws_cdk.aws_sqs._QueueBaseProxy instead

Any hints on how to potentially use that construct and properly set the reference to an already existing Queue?


Solution

  • Existing is a misnomer, it means that the queue exists in your CDK app, as opposed to being created by the EventbridgeToSqs construct. You cannot use an imported Queue, that's why the expected type is Queue, not IQueue.

    from_queue_arn returns an instance of IQueue, not Queue, and cannot be used here.