user14055005
user14055005

Reputation:

List the SNS topic using boto3

Im trying to list the sns topic using boto3

im using this code

import boto3
import pprint

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


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

but im geting this error

 File "kri.py", line 14
    print(each_reg['topic])
                          ^
SyntaxError: EOL while scanning string literal

Upvotes: 0

Views: 1861

Answers (2)

Rajnish kumar
Rajnish kumar

Reputation: 196

It should be:

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

and you need to import sns too.

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

Updated:

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'])

Upvotes: 2

Robert Kossendey
Robert Kossendey

Reputation: 6988

It should be

  print(each_reg['topic'])

You are missing a single quote.

Upvotes: 0

Related Questions