// Create new SQS Queue func (svc *AmazonSQS) CreateQueue(in *SDK.CreateQueueInput) error { data, err := svc.client.CreateQueue(in) if err != nil { log.Error("[SQS] Error on `CreateQueue` operation, queue="+*in.QueueName, err) return err } log.Info("[SQS] Complete CreateQueue, queue="+*in.QueueName, *(data.QueueUrl)) return nil }
// Create new DynamoDB table func (d *AmazonDynamoDB) CreateTable(in *SDK.CreateTableInput) error { data, err := d.client.CreateTable(in) if err != nil { log.Error("[DynamoDB] Error on `CreateTable` operation, table="+*in.TableName, err) return err } log.Info("[DynamoDB] Complete CreateTable, table="+*in.TableName, data.TableDescription.TableStatus) return nil }
// get infomation of the table func (d *AmazonDynamoDB) DescribeTable(name string) (*TableDescription, error) { req, err := d.client.DescribeTable(&SDK.DescribeTableInput{ TableName: String(name), }) if err != nil { log.Info("debug", err) return nil, err } return &TableDescription{req.Table}, nil }
// Delete DynamoDB table func (d *AmazonDynamoDB) DeleteTable(name string) error { in := &SDK.DeleteTableInput{ TableName: String(name), } data, err := d.client.DeleteTable(in) if err != nil { log.Error("[DynamoDB] Error on `DeleteTable` operation, table="+*in.TableName, err) return err } log.Info("[DynamoDB] Complete DeleteTable, table="+*in.TableName, data.TableDescription.TableStatus) return nil }
// Publish notification for arn(topic or endpoint) func (svc *AmazonSNS) Publish(arn string, msg string, opt map[string]interface{}) error { msg = truncateMessage(msg) m := make(map[string]string) m["default"] = msg m["GCM"] = composeMessageGCM(msg, opt) m["APNS"] = composeMessageAPNS(msg, opt) m["APNS_SANDBOX"] = m["APNS"] jsonString, _ := json.Marshal(m) resp, err := svc.Client.Publish(&SDK.PublishInput{ TargetArn: String(arn), Message: String(string(jsonString)), MessageStructure: String("json"), }) if err != nil { log.Error("[SNS] error on `Publish` operation, arn="+arn, err.Error()) return err } log.Info("[SNS] publish message", *resp.MessageId) return nil }
// Create new DynamoDB table func (d *AmazonDynamoDB) CreateTable(ct *CreateTableInput) error { if ct.HashKey == nil { err := NewError("cannot find hashkey on CreateTableInput") return err } var keys []*SDK.KeySchemaElement keys = append(keys, ct.HashKey) if ct.HasRangeKey() { keys = append(keys, ct.RangeKey) } tableName := d.TablePrefix + ct.Name tp := NewProvisionedThroughput(ct.ReadCapacity, ct.WriteCapacity) in := &SDK.CreateTableInput{ TableName: String(tableName), KeySchema: keys, AttributeDefinitions: ct.AttributeList(), ProvisionedThroughput: tp, } if ct.HasLSI() { in.LocalSecondaryIndexes = ct.ListLSI() } if ct.HasGSI() { in.GlobalSecondaryIndexes = ct.ListGSI() } out, err := d.client.CreateTable(in) if err != nil { log.Error("[DynamoDB] Error on `CreateTable` operation, table="+tableName, err) return err } desc := TableDescription{out.TableDescription} log.Info("[DynamoDB] Complete CreateTable, table="+tableName, desc.GetTableStatus()) return nil }