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

aws-cdk-lib/aws-sns-subscriptions: Cannot add SqsSubscription when using an Sqs Construct from a SymLinked Constructs Library #27225

Closed
gastonsilva opened this issue Sep 20, 2023 · 2 comments · Fixed by #27227
Labels
@aws-cdk/aws-sqs Related to Amazon Simple Queue Service bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@gastonsilva
Copy link
Contributor

Describe the bug

Users can't add an SqsSubscription to an Sns Topic using the "addSubscription" method when the created queue came from a symlinked constructs library

Expected Behavior

Users can add an SqsSubscription to an Sns Topic using the "addSubscription" method regardless of whether it came from a symlinked constructs library or not

Current Behavior

Stack trace:

Error: The supplied Queue object must be an instance of Construct
    at SqsSubscription.bind (/home/user/project/node_modules/aws-cdk-lib/aws-sns-subscriptions/lib/sqs.js:1:1024)
    at Topic.addSubscription (/home/user/project/node_modules/aws-cdk-lib/aws-sns/lib/topic-base.js:1:1018)
    at new NamedStack (/home/user/project/lib/SomeStack.ts:10:10) ...

Reproduction Steps

  1. npm link a construct library locally that has a sqs queue construct.
  2. Create a new sqs queue from that construct library
  3. Create an SNS topic using new Topic
  4. Add a new sqs subscription to the topic using the addSubscription method and new SqsSubscription
  5. run cdk synth

Example code:

const queue = new QueueFromSymLinkedLibrary(this, 'Queue');
const topic = new Topic(this, 'Topic');
topic.addSubscription(new SqsSubscription(queue));

Possible Solution

public bind(topic: sns.ITopic): sns.TopicSubscriptionConfig {
// Create subscription under *consuming* construct to make sure it ends up
// in the correct stack in cases of cross-stack subscriptions.
if (!(this.queue instanceof Construct)) {
throw new Error('The supplied Queue object must be an instance of Construct');
}

This guard clause should be:

    if (!Construct.isConstruct(this.queue)) {
      throw new Error('The supplied Queue object must be an instance of Construct');
    }

Reference: aws/constructs@bef8e4d

Additional Information/Context

No response

CDK CLI Version

2.93.0

Framework Version

No response

Node.js Version

18

OS

Ubuntu 22.04.3 LTS

Language

Typescript

Language Version

4.9.5

Other information

No response

@gastonsilva gastonsilva added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 20, 2023
@github-actions github-actions bot added the @aws-cdk/aws-sqs Related to Amazon Simple Queue Service label Sep 20, 2023
@peterwoodworth
Copy link
Contributor

Thanks for the research into this and the pull request! It's much appreciated 🙂

@peterwoodworth peterwoodworth added p1 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Sep 20, 2023
@mergify mergify bot closed this as completed in #27227 Oct 5, 2023
mergify bot pushed a commit that referenced this issue Oct 5, 2023
…Construct from a different Constructs library (#27227)

Fix the "is construct" check to ensure one can add an SqsSubscription to an sns topic using the "addSubscription" method regardless of whether it came from a symlinked construct library or not.

Closes #27225 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Oct 5, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

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
@aws-cdk/aws-sqs Related to Amazon Simple Queue Service bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
2 participants