Warm tip: This article is reproduced from serverfault.com, please click

python-使用boto3列出SNS主题

(python - List the SNS topic using boto3)

发布于 2020-12-02 13:07:01

我正在尝试使用boto3列出sns主题

我正在使用此代码

import boto3
import pprint

response = client.list_topics(
    NextToken='string'
)


list_topics=[]
for each_reg in response['topic']:
    print(each_reg['topic])

但我收到此错误

 File "kri.py", line 14
    print(each_reg['topic])
                          ^
SyntaxError: EOL while scanning string literal
Questioner
user14055005
Viewed
0
Rajnish kumar 2020-12-02 22:14:30

它应该是:

list_topics=[]
for each_reg in response['topic']:
    print(each_reg['topic'])

并且你也需要导入sns

client = boto3.client('sns', region_name='us-east-1') # add your region_name here

更新:

import boto3
client = boto3.client('sns', region_name='us-east-1')
response = client.list_topics()

for each_reg in response['Topics']:
    print(each_reg['TopicArn'])