I would like to connect an sqs queue to an sns topic that is in a different account, using cdk (typescript). Below is the code (this code is in a stack) that I think should work but I have some doubts listed below the code (I have not deployed this yet, still trying to learn how to do this first).
const topic = Topic.fromTopicArn(
this,
`${stackName}-topic`,
`arn:aws:sns:${region}:${accountno}:SubscriptionChanges`
);
topic.addSubscription(
new SqsSubscription(queue, {
filterPolicy: {
type: SubscriptionFilter.stringFilter({
whitelist: [
'filter1',
],
})
},
})
);
}
- I use fromTopicArn to initiate the topic construct. Am I allowed to do this if I am not the owner of the topic (the topic is defined in a different account so I am trying to do this cross account)?
- Is there a way to create a sqs subscription without creating the topic variable on the first line above?
I have read the documentation, and, there is example code for this, but it only shows how to do this within the same account. Anyone with any experience of this?