コード例 #1
0
ファイル: customizations_test.go プロジェクト: trayio/bunny
func TestCopySnapshotPresignedURL(t *testing.T) {
	svc := ec2.New(&aws.Config{Region: "us-west-2"})

	assert.NotPanics(t, func() {
		// Doesn't panic on nil input
		req, _ := svc.CopySnapshotRequest(nil)
		req.Sign()
	})

	req, _ := svc.CopySnapshotRequest(&ec2.CopySnapshotInput{
		SourceRegion:     aws.String("us-west-1"),
		SourceSnapshotID: aws.String("snap-id"),
	})
	req.Sign()

	b, _ := ioutil.ReadAll(req.HTTPRequest.Body)
	q, _ := url.ParseQuery(string(b))
	url, _ := url.QueryUnescape(q.Get("PresignedUrl"))
	assert.Equal(t, "us-west-2", q.Get("DestinationRegion"))
	assert.Regexp(t, `^https://ec2\.us-west-1\.amazon.+&DestinationRegion=us-west-2`, url)
}
コード例 #2
0
ファイル: nodes.go プロジェクト: trayio/bunny
// Collect gathers all running AWS instances with a specific tag.
// Returns hostname tags in array of *Node structs.
func Collect(cfg *aws.Config) []*Node {
	svc := ec2.New(cfg)
	nodes := make([]*Node, 0)

	params := &ec2.DescribeInstancesInput{
		Filters: []*ec2.Filter{
			{
				Name:   aws.String("tag:group"),
				Values: []*string{aws.String("rabbits-production")},
			},
			{
				Name:   aws.String("instance-state-name"),
				Values: []*string{aws.String("running")},
			},
		},
	}

	resp, err := svc.DescribeInstances(params)
	if err != nil {
		log.Println("Error while collecting nodes:", err)
	}

	if len(resp.Reservations) > 0 {
		for _, reservation := range resp.Reservations {
			for _, instance := range reservation.Instances {
				for _, tag := range instance.Tags {
					if *tag.Key == "hostname" {
						nodes = append(nodes, &Node{Host: *tag.Value})
					}
				}
			}
		}
	}

	return nodes
}
コード例 #3
0
ファイル: interface_test.go プロジェクト: trayio/bunny
func TestInterface(t *testing.T) {
	assert.Implements(t, (*ec2iface.EC2API)(nil), ec2.New(nil))
}