func (s *AmazonServer) SetUp(c *gocheck.C) { auth, err := aws.EnvAuth() if err != nil { c.Fatal(err) } s.auth = auth }
func ExampleV4Signer() { // Get auth from env vars auth, err := aws.EnvAuth() if err != nil { fmt.Println(err) } // Create a signer with the auth, name of the service, and aws region signer := aws.NewV4Signer(auth, "dynamodb", aws.USEast) // Create a request req, err := http.NewRequest("POST", aws.USEast.DynamoDBEndpoint, strings.NewReader("sample_request")) if err != nil { fmt.Println(err) } // Date or x-amz-date header is required to sign a request req.Header.Add("Date", time.Now().UTC().Format(http.TimeFormat)) // Sign the request signer.Sign(req) // Issue signed request http.DefaultClient.Do(req) }
func TestBasicGroupRequest(t *testing.T) { var as *AutoScaling awsAuth, err := aws.EnvAuth() if err != nil { mockTest = true t.Log("Running mock tests as AWS environment variables are not set") awsAuth := aws.Auth{AccessKey: "abc", SecretKey: "123"} as = New(awsAuth, aws.Region{AutoScalingEndpoint: testServer.URL}) testServer.Start() go testServer.WaitRequest() testServer.Response(200, nil, BasicGroupResponse) } else { as = New(awsAuth, aws.USWest2) } groupResp, err := as.DescribeAutoScalingGroups(nil, 10, "") if err != nil { t.Fatal(err) } if len(groupResp.AutoScalingGroups) > 0 { firstGroup := groupResp.AutoScalingGroups[0] if len(firstGroup.AutoScalingGroupName) > 0 { t.Logf("Found AutoScaling group %s\n", firstGroup.AutoScalingGroupName) } } testServer.Flush() }
func (s *S) TestEnvAuthAlt(c *gocheck.C) { os.Clearenv() os.Setenv("AWS_SECRET_KEY", "secret") os.Setenv("AWS_ACCESS_KEY", "access") auth, err := aws.EnvAuth() c.Assert(err, gocheck.IsNil) c.Assert(auth, gocheck.Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"}) }
func (s *SuiteI) SetUpSuite(c *gocheck.C) { if !*integration { c.Skip("Integration tests not enabled (-i flag)") } auth, err := aws.EnvAuth() if err != nil { c.Fatal(err.Error()) } s.auth = auth }
func (s *LiveSuite) SetUpSuite(c *gocheck.C) { if !Amazon { c.Skip("amazon tests not enabled (-amazon flag)") } auth, err := aws.EnvAuth() if err != nil { c.Fatal(err.Error()) } s.auth = auth }
func setUpAuth(c *gocheck.C) { if !*amazon { c.Skip("Test against amazon not enabled.") } if *local { c.Log("Using local server") dynamodb_region = aws.Region{DynamoDBEndpoint: "http://127.0.0.1:8000"} dynamodb_auth = aws.Auth{AccessKey: "DUMMY_KEY", SecretKey: "DUMMY_SECRET"} } else { c.Log("Using REAL AMAZON SERVER") dynamodb_region = aws.USEast auth, err := aws.EnvAuth() if err != nil { c.Fatal(err) } dynamodb_auth = auth } }
func (s *S) TestEnvAuthNoAccess(c *gocheck.C) { os.Clearenv() os.Setenv("AWS_SECRET_ACCESS_KEY", "foo") _, err := aws.EnvAuth() c.Assert(err, gocheck.ErrorMatches, "AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY not found in environment") }
func (s *S) TestEnvAuthNoSecret(c *gocheck.C) { os.Clearenv() _, err := aws.EnvAuth() c.Assert(err, gocheck.ErrorMatches, "AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY not found in environment") }
func TestAutoScalingGroup(t *testing.T) { var as *AutoScaling // Launch configuration test config lc := new(LaunchConfiguration) lc.LaunchConfigurationName = "LConf1" lc.ImageId = "ami-03e47533" // Octave debian ami lc.KernelId = "aki-98e26fa8" lc.KeyName = "testAWS" // Replace with valid key for your account lc.InstanceType = "m1.small" // CreateAutoScalingGroup params test config asgReq := new(CreateAutoScalingGroupParams) asgReq.AutoScalingGroupName = "ASGTest1" asgReq.LaunchConfigurationName = lc.LaunchConfigurationName asgReq.DefaultCooldown = 300 asgReq.HealthCheckGracePeriod = 300 asgReq.DesiredCapacity = 1 asgReq.MinSize = 1 asgReq.MaxSize = 5 asgReq.AvailabilityZones = []string{"us-west-2a"} asg := new(AutoScalingGroup) asg.AutoScalingGroupName = "ASGTest1" asg.LaunchConfigurationName = lc.LaunchConfigurationName asg.DefaultCooldown = 300 asg.HealthCheckGracePeriod = 300 asg.DesiredCapacity = 1 asg.MinSize = 1 asg.MaxSize = 5 asg.AvailabilityZones = []string{"us-west-2a"} awsAuth, err := aws.EnvAuth() if err != nil { mockTest = true t.Log("Running mock tests as AWS environment variables are not set") awsAuth := aws.Auth{AccessKey: "abc", SecretKey: "123"} as = New(awsAuth, aws.Region{AutoScalingEndpoint: testServer.URL}) } else { as = New(awsAuth, aws.USWest2) } // Create the launch configuration if mockTest { testServer.Response(200, nil, CreateLaunchConfigurationResponse) } _, err = as.CreateLaunchConfiguration(lc) if err != nil { t.Fatal(err) } // Check that we can get the launch configuration details if mockTest { testServer.Response(200, nil, DescribeLaunchConfigurationsResponse) } _, err = as.DescribeLaunchConfigurations([]string{lc.LaunchConfigurationName}, 10, "") if err != nil { t.Fatal(err) } // Create the AutoScalingGroup if mockTest { testServer.Response(200, nil, CreateAutoScalingGroupResponse) } _, err = as.CreateAutoScalingGroup(asgReq) if err != nil { t.Fatal(err) } // Check that we can get the autoscaling group details if mockTest { testServer.Response(200, nil, DescribeAutoScalingGroupsResponse) } _, err = as.DescribeAutoScalingGroups(nil, 10, "") if err != nil { t.Fatal(err) } // Suspend the scaling processes for the test AutoScalingGroup if mockTest { testServer.Response(200, nil, SuspendProcessesResponse) } _, err = as.SuspendProcesses(asg.AutoScalingGroupName, nil) if err != nil { t.Fatal(err) } // Resume scaling processes for the test AutoScalingGroup if mockTest { testServer.Response(200, nil, ResumeProcessesResponse) } _, err = as.ResumeProcesses(asg.AutoScalingGroupName, nil) if err != nil { t.Fatal(err) } // Change the desired capacity from 1 to 2. This will launch a second instance if mockTest { testServer.Response(200, nil, SetDesiredCapacityResponse) } _, err = as.SetDesiredCapacity(asg.AutoScalingGroupName, 2, false) if err != nil { t.Fatal(err) } // Change the desired capacity from 2 to 1. This will terminate one of the instances if mockTest { testServer.Response(200, nil, SetDesiredCapacityResponse) } _, err = as.SetDesiredCapacity(asg.AutoScalingGroupName, 1, false) if err != nil { t.Fatal(err) } // Update the max capacity for the scaling group if mockTest { testServer.Response(200, nil, UpdateAutoScalingGroupResponse) } asg.MinSize = 1 asg.MaxSize = 6 asg.DesiredCapacity = 1 _, err = as.UpdateAutoScalingGroup(asg) if err != nil { t.Fatal(err) } // Add a scheduled action to the group psar := new(PutScheduledUpdateGroupActionParams) psar.AutoScalingGroupName = asg.AutoScalingGroupName psar.MaxSize = 4 psar.ScheduledActionName = "SATest1" psar.Recurrence = "30 0 1 1,6,12 *" if mockTest { testServer.Response(200, nil, PutScheduledUpdateGroupActionResponse) } _, err = as.PutScheduledUpdateGroupAction(psar) if err != nil { t.Fatal(err) } // List the scheduled actions for the group sar := new(DescribeScheduledActionsParams) sar.AutoScalingGroupName = asg.AutoScalingGroupName if mockTest { testServer.Response(200, nil, DescribeScheduledActionsResponse) } _, err = as.DescribeScheduledActions(sar) if err != nil { t.Fatal(err) } // Delete the test scheduled action from the group if mockTest { testServer.Response(200, nil, DeleteScheduledActionResponse) } _, err = as.DeleteScheduledAction(asg.AutoScalingGroupName, psar.ScheduledActionName) if err != nil { t.Fatal(err) } testServer.Flush() }