Listing Your Amazon SNS Topics - AWS SDK for Go (version 1)

We announced the upcoming end-of-support for AWS SDK for Go V1. We recommend that you migrate to AWS SDK for Go V2. For dates, additional details, and information on how to migrate, please refer to the linked announcement.

Listing Your Amazon SNS Topics

The following example lists the ARNs of your Amazon SNS topics in your default region.

package main import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sns" "fmt" "os" ) func main() { // Initialize a session that the SDK will use to load // credentials from the shared credentials file. (~/.aws/credentials). sess := session.Must(session.NewSessionWithOptions(session.Options{ SharedConfigState: session.SharedConfigEnable, })) svc := sns.New(sess) result, err := svc.ListTopics(nil) if err != nil { fmt.Println(err.Error()) os.Exit(1) } for _, t := range result.Topics { fmt.Println(*t.TopicArn) } }

See the complete example on GitHub.