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) }
// Communicate with all EC2 endpoints to see if they are alive. func (s *ClientTests) TestRegions(c *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, Matches, "InvalidGroup.NotFound") } else { c.Errorf("Non-EC2 error: %s", err) } } else { c.Errorf("Test should have errored but it seems to have succeeded") } } }
func amis(args *docopt.Args) { auth, err := aws.EnvAuth() if err != nil { log.Fatal(err) } manifest := &EC2Manifest{} if err := json.NewDecoder(os.Stdin).Decode(manifest); err != nil { log.Fatal(err) } for _, s := range strings.Split(args.String["<ids>"], ",") { regionID := strings.SplitN(s, ":", 2) resp, err := ec2.New(auth, aws.Regions[regionID[0]]).Images([]string{regionID[1]}, nil) if err != nil { log.Fatal(err) } if len(resp.Images) < 1 { log.Fatalln("Could not find image", regionID[1]) } image := resp.Images[0] var snapshotID string for _, mapping := range image.BlockDevices { if mapping.DeviceName == image.RootDeviceName { snapshotID = mapping.SnapshotId } } if snapshotID == "" { log.Fatalln("Could not determine RootDeviceSnapshotID for", regionID[1]) } manifest.Add(args.String["<version>"], &EC2Image{ ID: image.Id, Name: image.Name, Region: regionID[0], OwnerID: image.OwnerId, RootDeviceType: image.RootDeviceType, RootDeviceName: image.RootDeviceName, RootDeviceSnapshotID: snapshotID, VirtualizationType: image.VirtualizationType, Hypervisor: image.Hypervisor, }) } if err := json.NewEncoder(os.Stdout).Encode(manifest); err != nil { log.Fatal(err) } }
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="}) }
func (s *LocalServerSuite) SetUpSuite(c *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) }
func (s *S) SetUpSuite(c *C) { testServer.Start() auth := aws.Auth{"abc", "123"} s.ec2 = ec2.New(auth, aws.Region{EC2Endpoint: testServer.URL}) }