[英]Subscribe a sqs queue to a sns topic that is in a different account, using aws cdk(typescript)
[英]How to subscribe an SNS topic of one account by SQS of another account using boto3?
我正在尝试在一个帐户中创建一个SNS主题并将其附加到配置规则。 我有3个这样的帐户,并希望在每个帐户中创建SNS主题。 现在我想通过第四个帐户的SQS订阅3个不同帐户的所有3个主题。
我可以手动完成。 有人可以告诉我如何通过boto3完成。
提前致谢。
为了使用boto3通过账户B中存在的SQS订阅账户A中存在的SNS主题,以下是该过程。
在帐户A中,创建SNS主题并添加适当的权限。 例如,
import boto3
sns_client = boto3.clien('sns')
topics = sns_client.create_topic(Name='SNS topic name')
sns_client.add_permission(
TopicArn=str(topics['TopicArn']),
Label=label,
AWSAccountId=[
"AccountB_Id",
],
ActionName=[
"GetTopicAttributes",
"SetTopicAttributes",
"AddPermission",
"RemovePermission",
"DeleteTopic",
"Subscribe",
"ListSubscriptionsByTopic",
"Publish",
"Receive"
]
)
现在,要从帐户B订阅创建的主题,请从帐户B执行以下代码。
import boto3
subscription_client = boto3.client('sns')
subscription_client.subscribe(
TopicArn="ARN of the topic created",
Protocol="sqs",
Endpoint="ARN of the SQS present in Account B"
)
现在您将看到帐户A的SNS主题已被帐户B订阅。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.