本文整理汇总了Golang中github.com/crowdmob/goamz/ec2.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestRegions
// Communicate with all EC2 endpoints to see if they are alive.
func (s *ClientTests) TestRegions(c *check.C) {
name := sessionName("goamz-region-test")
perms := []ec2.IPPerm{{
Protocol: "tcp",
FromPort: 80,
ToPort: 80,
SourceIPs: []string{"127.0.0.1/32"},
}}
errs := make(chan error, len(allRegions))
for _, region := range allRegions {
go func(r aws.Region) {
e := ec2.New(s.ec2.Auth, r)
_, err := e.AuthorizeSecurityGroup(ec2.SecurityGroup{Name: name}, perms)
errs <- err
}(region)
}
for _ = range allRegions {
err := <-errs
if err != nil {
ec2_err, ok := err.(*ec2.Error)
if ok {
c.Check(ec2_err.Code, check.Matches, "InvalidGroup.NotFound")
} else {
c.Errorf("Non-EC2 error: %s", err)
}
} else {
c.Errorf("Test should have errored but it seems to have succeeded")
}
}
}
示例2: SetUpSuite
func (s *AmazonClientSuite) SetUpSuite(c *check.C) {
if !testutil.Amazon {
c.Skip("AmazonClientSuite tests not enabled")
}
s.srv.SetUp(c)
s.ec2 = ec2.New(s.srv.auth, aws.USEast)
}
示例3: main
func main() {
kingpin.Version("1.2.1")
kingpin.Parse()
sl, err := syslog.New(syslog.LOG_NOTICE|syslog.LOG_LOCAL0, "[varnish-purge-proxy]")
defer sl.Close()
if err != nil {
log.Println("Error writing to syslog")
} else {
log.SetFlags(0)
log.SetOutput(sl)
}
if len(*tags) == 0 {
fmt.Println("No tags specified")
return
}
// Set up access to ec2
auth, err := aws.GetAuth("", "", "", time.Now().Add(time.Duration(24*365*time.Hour)))
if err != nil {
log.Println(err)
return
}
ec2region := ec2.New(auth, region)
go serveHTTP(*port, ec2region)
select {}
}
示例4: SetUpSuite
func (s *AmazonServerSuite) SetUpSuite(c *C) {
if !testutil.Amazon {
c.Skip("AmazonServerSuite tests not enabled")
}
s.srv.SetUp(c)
s.ServerTests.ec2 = ec2.New(s.srv.auth, aws.USEast)
}
示例5: SetUpSuite
func (s *AmazonClientSuite) SetUpSuite(c *C) {
if !*amazon {
c.Skip("AmazonClientSuite tests not enabled")
}
s.srv.SetUp(c)
s.elb = elb.New(s.srv.auth, aws.USEast)
s.ec2 = ec2.New(s.srv.auth, aws.USEast)
}
示例6: TestSignatureWithEndpointPath
func (s *S) TestSignatureWithEndpointPath(c *check.C) {
ec2.FakeTime(true)
defer ec2.FakeTime(false)
testServer.Response(200, nil, RebootInstancesExample)
// https://bugs.launchpad.net/goamz/+bug/1022749
ec2 := ec2.New(s.ec2.Auth, aws.Region{EC2Endpoint: testServer.URL + "/services/Cloud"})
_, err := ec2.RebootInstances("i-10a64379")
c.Assert(err, check.IsNil)
req := testServer.WaitRequest()
c.Assert(req.Form["Signature"], check.DeepEquals, []string{"VVoC6Y6xfES+KvZo+789thP8+tye4F6fOKBiKmXk4S4="})
}
示例7: TestSignatureWithEndpointPath
func (s *S) TestSignatureWithEndpointPath(c *gocheck.C) {
ec2.FakeTime(true)
defer ec2.FakeTime(false)
testServer.Response(200, nil, RebootInstancesExample)
// https://bugs.launchpad.net/goamz/+bug/1022749
ec2 := ec2.New(s.ec2.Auth, aws.Region{EC2Endpoint: testServer.URL + "/services/Cloud"})
_, err := ec2.RebootInstances("i-10a64379")
c.Assert(err, gocheck.IsNil)
req := testServer.WaitRequest()
c.Assert(req.Form["Signature"], gocheck.DeepEquals, []string{"klxs+VwDa1EKHBsxlDYYN58wbP6An+RVdhETv1Fm/os="})
}
示例8: TestSignatureWithEndpointPath
func (s *S) TestSignatureWithEndpointPath(c *C) {
ec2.FakeTime(true)
defer ec2.FakeTime(false)
testServer.Response(200, nil, RebootInstancesExample)
// https://bugs.launchpad.net/goamz/+bug/1022749
ec2 := ec2.New(s.ec2.Auth, aws.Region{EC2Endpoint: testServer.URL + "/services/Cloud"})
_, err := ec2.RebootInstances("i-10a64379")
c.Assert(err, IsNil)
req := testServer.WaitRequest()
c.Assert(req.Form["Signature"], DeepEquals, []string{"gdG/vEm+c6ehhhfkrJy3+wuVzw/rzKR42TYelMwti7M="})
}
示例9: main
func main() {
flag.Parse()
auth, err := aws.GetAuth("", "", "", time.Now().Add(time.Hour))
if err != nil {
panic(err)
}
filter := ec2.NewFilter()
filter.Add("instance-state-name", "running")
filter.Add("tag:env", "prod")
c := ec2.New(auth, aws.USEast)
resp, err := c.DescribeInstances(nil, filter)
if err != nil {
log.Panicln(err)
}
rezzies := resp.Reservations
for _, rv := range rezzies {
for _, inst := range rv.Instances {
if len(inst.BlockDevices) < 3 {
for _, bd := range inst.BlockDevices {
vid := bd.EBS.VolumeId
name, err := getName(inst.Tags)
log.Printf("Creating snapshot for: %s volume: %v\n", name, vid)
if err != nil {
log.Fatalf("Error getting name:", err)
}
stamp := time.Now().UTC().Format(TIME_FORMAT)
snprsp, err := c.CreateSnapshot(vid, fmt.Sprintf("%s %s %s", name, *period, stamp))
if err != nil {
log.Printf("Failed to snap: %s, Error: %s\n", vid, err)
break
} else {
log.Printf("Created snap: %s\n", snprsp.Id)
t := ec2.Tag{Key: "inst_snap", Value: fmt.Sprintf("%s/%s", inst.InstanceId, *period)}
tags = append(inst.Tags, t)
wg.Add(1)
go tagSnapshot(inst.InstanceId, snprsp.Id, tags, c)
}
}
}
}
}
wg.Wait()
}
示例10: SetUpSuite
func (s *LocalServerSuite) SetUpSuite(c *gocheck.C) {
s.srv.SetUp(c)
s.ServerTests.ec2 = ec2.New(s.srv.auth, s.srv.region)
s.clientTests.ec2 = ec2.New(s.srv.auth, s.srv.region)
}
示例11: SetUpSuite
func (s *S) SetUpSuite(c *check.C) {
testServer.Start()
auth := aws.Auth{AccessKey: "abc", SecretKey: "123"}
s.ec2 = ec2.New(auth, aws.Region{EC2Endpoint: testServer.URL})
}
示例12: getInstanceStatus
func getInstanceStatus(region string, auth *aws.Auth, instances []string, filter *ec2.Filter) ([]ec2.InstanceStatus, error) {
endpoint := "https://ec2." + region + ".amazonaws.com"
ec2 := ec2.New(*auth, aws.Region{EC2Endpoint: endpoint})
resp, err := ec2.DescribeInstanceStatus(nil, filter)
return resp.InstanceStatuses, err
}
示例13: SetUpSuite
func (s *S) SetUpSuite(c *C) {
testServer.Start()
auth := aws.Auth{"abc", "123"}
s.ec2 = ec2.New(auth, aws.Region{EC2Endpoint: testServer.URL})
}