9 "github.com/aws/aws-sdk-go/aws"
10 "github.com/aws/aws-sdk-go/aws/credentials"
11 "github.com/aws/aws-sdk-go/aws/endpoints"
12 "github.com/aws/aws-sdk-go/aws/session"
13 "github.com/aws/aws-sdk-go/service/sns"
17 topic := flag.String("t", "", "The name of the topic")
18 attributes := flag.String("a", "", "Topic attributes needed")
21 attributesmap := map[string]*string{}
22 err := json.Unmarshal([]byte(*attributes), &attributesmap) // convert JSON string to Go map
24 exitErrorf("Check your JSON String for any errors: %s : %s", err, *attributes)
28 fmt.Println("You must supply the name of the topic")
29 fmt.Println("-t TOPIC")
33 if *attributes == "" {
34 fmt.Println("You must supply topic attributes")
35 fmt.Println("-a ATTRIBUTES")
38 //Ceph RGW Cluster credentials
39 access_key := "0555b35654ad1656d804"
40 secret_key := "h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q=="
42 url := "http://127.0.0.1:8000"
44 defaultResolver := endpoints.DefaultResolver()
45 snsCustResolverFn := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
47 return endpoints.ResolvedEndpoint{
52 return defaultResolver.EndpointFor(service, region, optFns...)
55 sess := session.Must(session.NewSessionWithOptions(session.Options{
57 Region: aws.String("default"),
58 Credentials: credentials.NewStaticCredentials(access_key, secret_key, token_id),
59 S3ForcePathStyle: aws.Bool(true),
60 EndpointResolver: endpoints.ResolverFunc(snsCustResolverFn),
64 client := sns.New(sess)
66 results, err := client.CreateTopic(&sns.CreateTopicInput{
67 Attributes: attributesmap,
72 exitErrorf("Unable to create topic %s, %s", *topic, err)
75 fmt.Printf("Succesfully created %s \n", *results.TopicArn)
78 func exitErrorf(msg string, args ...interface{}) {
79 fmt.Fprintf(os.Stderr, msg+"\n", args...)