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) }
// 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") } } }
func (e EC2Tags) Get() (map[string]string, error) { tags := make(map[string]string) // Passing blank values here instructs the AWS library to look at the // current instances meta data for the security credentials. auth, err := aws.GetAuth("", "", "", time.Time{}) if err != nil { return tags, errors.New(fmt.Sprintf("Error creating AWS authentication: %s", err.Error())) } // Find the current region and create a new EC2 connection region := aws.GetRegion(aws.InstanceRegion()) ec2Client := ec2.New(auth, region) // Filter by the current machines instance-id filter := ec2.NewFilter() filter.Add("resource-id", aws.InstanceId()) // Describe the tags for the current instance resp, err := ec2Client.DescribeTags(filter) if err != nil { return tags, errors.New(fmt.Sprintf("Error downloading tags: %s", err.Error())) } // Collect the tags for _, tag := range resp.Tags { tags[tag.Key] = tag.Value } return tags, nil }
func (s *S) TestSignatureWithEndpointPath(c *check.C) { ec2.FakeTime(true) defer ec2.FakeTime(false) testServer.Response(200, nil, RebootInstancesExample) region := aws.Region{EC2Endpoint: aws.ServiceInfo{Endpoint: testServer.URL + "/services/Cloud", Signer: aws.V2Signature}} ec2 := ec2.New(s.ec2.Auth, region) _, 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="}) }
func RemoveIPFromGroup(p string, s string, secGroup string) error { auth := aws.Auth{AccessKey: p, SecretKey: s} region := aws.USEast ec2item := ec2.New(auth, region) g := ec2.SecurityGroup{Id: secGroup} ipperm := ec2.IPPerm{} ipperm.Protocol = "tcp" ipperm.FromPort = 5432 ipperm.ToPort = 5432 ipperm.SourceIPs = []string{fmt.Sprintf("%v/24", lambdaIP)} perms := []ec2.IPPerm{ipperm} _, errRevoke := ec2item.RevokeSecurityGroup(g, perms) if errRevoke != nil { log.Println("ERROR:", errRevoke) } else { log.Println("Complete! Revoked! for:", lambdaIP) } return errRevoke }
func (s *S) SetUpSuite(c *check.C) { testServer.Start() auth := aws.Auth{AccessKey: "abc", SecretKey: "123"} s.ec2 = ec2.New(auth, aws.Region{EC2Endpoint: aws.ServiceInfo{Endpoint: testServer.URL, Signer: aws.V2Signature}}) }
func (s *LocalServerSuite) SetUpSuite(c *check.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) }