func getSqsQueueSize(region, awsAccessKeyID, awsSecretAccessKey, queueName string) (int, error) {
	// Auth
	auth, err := aws.GetAuth(awsAccessKeyID, awsSecretAccessKey, "", time.Now())
	if err != nil {
		return -1, err
	}

	// SQS
	sqsClient := sqs.New(auth, aws.GetRegion(region))
	queue, err := sqsClient.GetQueue(queueName)
	if err != nil {
		return -1, err
	}

	// Get queue attribute
	attr, err := queue.GetQueueAttributes(sqsAttributeOfQueueSize)
	if err != nil {
		return -1, err
	}

	// Queue size
	size, err := strconv.Atoi(attr.Attributes[0].Value)
	if err != nil {
		return -1, err
	}

	return size, nil
}
Ejemplo n.º 2
0
func getQueue(name, public, secret string) (*sqs.Queue, error) {
	auth := aws.Auth{AccessKey: public, SecretKey: secret}
	region := aws.Region{}
	region.Name = "us-east-1"
	region.SQSEndpoint = "http://sqs.us-east-1.amazonaws.com"
	SQS = sqs.New(auth, region)
	if SQS == nil {
		return nil, fmt.Errorf("Can't get sqs reference for %v %v", auth, region)
	}
	return SQS.GetQueue(name)
}
Ejemplo n.º 3
0
func main() {
	auth, err := aws.GetAuth("", "", "", time.Time{})
	check(err)
	s := sqs.New(auth, aws.Regions["us-east-1"])
	for _, qn := range queues {
		q, err := s.GetQueue(qn)
		if err != nil {
			fmt.Printf("error for queue %s: %v\n", qn, err)
			continue
		}
		for _, an := range attrs {
			a, err := q.GetQueueAttributes(an)
			if err != nil {
				fmt.Printf(
					"error getting attribute %s for queue %s: %v\n",
					an, qn, err)
				continue
			}
			fmt.Printf(
				"%s.%s: %s\n",
				qn, a.Attributes[0].Name, a.Attributes[0].Value)
		}
	}
}