簡體   English   中英

如何使用boto3通過另一個帳戶的SQS訂閱一個帳戶的SNS主題?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM