func ExampleAutoScaling_CreateLaunchConfiguration() { svc := autoscaling.New(nil) params := &autoscaling.CreateLaunchConfigurationInput{ LaunchConfigurationName: aws.String("XmlStringMaxLen255"), // Required AssociatePublicIpAddress: aws.Bool(true), BlockDeviceMappings: []*autoscaling.BlockDeviceMapping{ { // Required DeviceName: aws.String("XmlStringMaxLen255"), // Required Ebs: &autoscaling.Ebs{ DeleteOnTermination: aws.Bool(true), Iops: aws.Int64(1), SnapshotId: aws.String("XmlStringMaxLen255"), VolumeSize: aws.Int64(1), VolumeType: aws.String("BlockDeviceEbsVolumeType"), }, NoDevice: aws.Bool(true), VirtualName: aws.String("XmlStringMaxLen255"), }, // More values... }, ClassicLinkVPCId: aws.String("XmlStringMaxLen255"), ClassicLinkVPCSecurityGroups: []*string{ aws.String("XmlStringMaxLen255"), // Required // More values... }, EbsOptimized: aws.Bool(true), IamInstanceProfile: aws.String("XmlStringMaxLen1600"), ImageId: aws.String("XmlStringMaxLen255"), InstanceId: aws.String("XmlStringMaxLen16"), InstanceMonitoring: &autoscaling.InstanceMonitoring{ Enabled: aws.Bool(true), }, InstanceType: aws.String("XmlStringMaxLen255"), KernelId: aws.String("XmlStringMaxLen255"), KeyName: aws.String("XmlStringMaxLen255"), PlacementTenancy: aws.String("XmlStringMaxLen64"), RamdiskId: aws.String("XmlStringMaxLen255"), SecurityGroups: []*string{ aws.String("XmlString"), // Required // More values... }, SpotPrice: aws.String("SpotPrice"), UserData: aws.String("XmlStringUserData"), } resp, err := svc.CreateLaunchConfiguration(params) if err != nil { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) return } // Pretty-print the response data. fmt.Println(resp) }
func ExampleAutoScaling_DeleteTags() { svc := autoscaling.New(nil) params := &autoscaling.DeleteTagsInput{ Tags: []*autoscaling.Tag{ // Required { // Required Key: aws.String("TagKey"), // Required PropagateAtLaunch: aws.Bool(true), ResourceId: aws.String("XmlString"), ResourceType: aws.String("XmlString"), Value: aws.String("TagValue"), }, // More values... }, } resp, err := svc.DeleteTags(params) if err != nil { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) return } // Pretty-print the response data. fmt.Println(resp) }
// Use S3 for simplicity func TestPaginationTruncation(t *testing.T) { count := 0 client := s3.New(nil) reqNum := &count resps := []*s3.ListObjectsOutput{ {IsTruncated: aws.Bool(true), Contents: []*s3.Object{{Key: aws.String("Key1")}}}, {IsTruncated: aws.Bool(true), Contents: []*s3.Object{{Key: aws.String("Key2")}}}, {IsTruncated: aws.Bool(false), Contents: []*s3.Object{{Key: aws.String("Key3")}}}, {IsTruncated: aws.Bool(true), Contents: []*s3.Object{{Key: aws.String("Key4")}}}, } client.Handlers.Send.Clear() // mock sending client.Handlers.Unmarshal.Clear() client.Handlers.UnmarshalMeta.Clear() client.Handlers.ValidateResponse.Clear() client.Handlers.Unmarshal.PushBack(func(r *request.Request) { r.Data = resps[*reqNum] *reqNum++ }) params := &s3.ListObjectsInput{Bucket: aws.String("bucket")} results := []string{} err := client.ListObjectsPages(params, func(p *s3.ListObjectsOutput, last bool) bool { results = append(results, *p.Contents[0].Key) return true }) assert.Equal(t, []string{"Key1", "Key2", "Key3"}, results) assert.Nil(t, err) // Try again without truncation token at all count = 0 resps[1].IsTruncated = nil resps[2].IsTruncated = aws.Bool(true) results = []string{} err = client.ListObjectsPages(params, func(p *s3.ListObjectsOutput, last bool) bool { results = append(results, *p.Contents[0].Key) return true }) assert.Equal(t, []string{"Key1", "Key2"}, results) assert.Nil(t, err) }
func ExampleELB_ModifyLoadBalancerAttributes() { svc := elb.New(nil) params := &elb.ModifyLoadBalancerAttributesInput{ LoadBalancerAttributes: &elb.LoadBalancerAttributes{ // Required AccessLog: &elb.AccessLog{ Enabled: aws.Bool(true), // Required EmitInterval: aws.Int64(1), S3BucketName: aws.String("S3BucketName"), S3BucketPrefix: aws.String("AccessLogPrefix"), }, AdditionalAttributes: []*elb.AdditionalAttribute{ { // Required Key: aws.String("StringVal"), Value: aws.String("StringVal"), }, // More values... }, ConnectionDraining: &elb.ConnectionDraining{ Enabled: aws.Bool(true), // Required Timeout: aws.Int64(1), }, ConnectionSettings: &elb.ConnectionSettings{ IdleTimeout: aws.Int64(1), // Required }, CrossZoneLoadBalancing: &elb.CrossZoneLoadBalancing{ Enabled: aws.Bool(true), // Required }, }, LoadBalancerName: aws.String("AccessPointName"), // Required } resp, err := svc.ModifyLoadBalancerAttributes(params) if err != nil { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) return } // Pretty-print the response data. fmt.Println(resp) }
func TestMultipleHandlers(t *testing.T) { r := &request.Request{} l := request.HandlerList{} l.PushBack(func(r *request.Request) { r.Data = nil }) l.PushFront(func(r *request.Request) { r.Data = aws.Bool(true) }) l.Run(r) if r.Data != nil { t.Error("Expected handler to execute") } }
func ExampleAutoScaling_CreateAutoScalingGroup() { svc := autoscaling.New(nil) params := &autoscaling.CreateAutoScalingGroupInput{ AutoScalingGroupName: aws.String("XmlStringMaxLen255"), // Required MaxSize: aws.Int64(1), // Required MinSize: aws.Int64(1), // Required AvailabilityZones: []*string{ aws.String("XmlStringMaxLen255"), // Required // More values... }, DefaultCooldown: aws.Int64(1), DesiredCapacity: aws.Int64(1), HealthCheckGracePeriod: aws.Int64(1), HealthCheckType: aws.String("XmlStringMaxLen32"), InstanceId: aws.String("XmlStringMaxLen16"), LaunchConfigurationName: aws.String("ResourceName"), LoadBalancerNames: []*string{ aws.String("XmlStringMaxLen255"), // Required // More values... }, PlacementGroup: aws.String("XmlStringMaxLen255"), Tags: []*autoscaling.Tag{ { // Required Key: aws.String("TagKey"), // Required PropagateAtLaunch: aws.Bool(true), ResourceId: aws.String("XmlString"), ResourceType: aws.String("XmlString"), Value: aws.String("TagValue"), }, // More values... }, TerminationPolicies: []*string{ aws.String("XmlStringMaxLen1600"), // Required // More values... }, VPCZoneIdentifier: aws.String("XmlStringMaxLen255"), } resp, err := svc.CreateAutoScalingGroup(params) if err != nil { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) return } // Pretty-print the response data. fmt.Println(resp) }
func TestNoErrors(t *testing.T) { input := &StructShape{ RequiredList: []*ConditionalStructShape{}, RequiredMap: map[string]*ConditionalStructShape{ "key1": {Name: aws.String("Name")}, "key2": {Name: aws.String("Name")}, }, RequiredBool: aws.Bool(true), OptionalStruct: &ConditionalStructShape{Name: aws.String("Name")}, } req := testSvc.NewRequest(&request.Operation{}, input, nil) corehandlers.ValidateParametersHandler.Fn(req) require.NoError(t, req.Error) }
func ExampleCloudWatch_PutMetricAlarm() { svc := cloudwatch.New(nil) params := &cloudwatch.PutMetricAlarmInput{ AlarmName: aws.String("AlarmName"), // Required ComparisonOperator: aws.String("ComparisonOperator"), // Required EvaluationPeriods: aws.Int64(1), // Required MetricName: aws.String("MetricName"), // Required Namespace: aws.String("Namespace"), // Required Period: aws.Int64(1), // Required Statistic: aws.String("Statistic"), // Required Threshold: aws.Float64(1.0), // Required ActionsEnabled: aws.Bool(true), AlarmActions: []*string{ aws.String("ResourceName"), // Required // More values... }, AlarmDescription: aws.String("AlarmDescription"), Dimensions: []*cloudwatch.Dimension{ { // Required Name: aws.String("DimensionName"), // Required Value: aws.String("DimensionValue"), // Required }, // More values... }, InsufficientDataActions: []*string{ aws.String("ResourceName"), // Required // More values... }, OKActions: []*string{ aws.String("ResourceName"), // Required // More values... }, Unit: aws.String("StandardUnit"), } resp, err := svc.PutMetricAlarm(params) if err != nil { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) return } // Pretty-print the response data. fmt.Println(resp) }
func TestMetadataNotAvailable(t *testing.T) { c := ec2metadata.New(nil) c.Handlers.Send.Clear() c.Handlers.Send.PushBack(func(r *request.Request) { r.HTTPResponse = &http.Response{ StatusCode: int(0), Status: http.StatusText(int(0)), Body: ioutil.NopCloser(bytes.NewReader([]byte{})), } r.Error = awserr.New("RequestError", "send request failed", nil) r.Retryable = aws.Bool(true) // network errors are retryable }) available := c.Available() assert.False(t, available) }
func TestNestedMissingRequiredParameters(t *testing.T) { input := &StructShape{ RequiredList: []*ConditionalStructShape{{}}, RequiredMap: map[string]*ConditionalStructShape{ "key1": {Name: aws.String("Name")}, "key2": {}, }, RequiredBool: aws.Bool(true), OptionalStruct: &ConditionalStructShape{}, } req := testSvc.NewRequest(&request.Operation{}, input, nil) corehandlers.ValidateParametersHandler.Fn(req) require.Error(t, req.Error) assert.Equal(t, "InvalidParameter", req.Error.(awserr.Error).Code()) assert.Equal(t, "3 validation errors:\n- missing required parameter: RequiredList[0].Name\n- missing required parameter: RequiredMap[\"key2\"].Name\n- missing required parameter: OptionalStruct.Name", req.Error.(awserr.Error).Message()) }
func ExampleAutoScaling_DeleteAutoScalingGroup() { svc := autoscaling.New(nil) params := &autoscaling.DeleteAutoScalingGroupInput{ AutoScalingGroupName: aws.String("ResourceName"), // Required ForceDelete: aws.Bool(true), } resp, err := svc.DeleteAutoScalingGroup(params) if err != nil { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) return } // Pretty-print the response data. fmt.Println(resp) }
func ExampleAutoScaling_TerminateInstanceInAutoScalingGroup() { svc := autoscaling.New(nil) params := &autoscaling.TerminateInstanceInAutoScalingGroupInput{ InstanceId: aws.String("XmlStringMaxLen16"), // Required ShouldDecrementDesiredCapacity: aws.Bool(true), // Required } resp, err := svc.TerminateInstanceInAutoScalingGroup(params) if err != nil { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) return } // Pretty-print the response data. fmt.Println(resp) }
func ExampleAutoScaling_SetInstanceHealth() { svc := autoscaling.New(nil) params := &autoscaling.SetInstanceHealthInput{ HealthStatus: aws.String("XmlStringMaxLen32"), // Required InstanceId: aws.String("XmlStringMaxLen16"), // Required ShouldRespectGracePeriod: aws.Bool(true), } resp, err := svc.SetInstanceHealth(params) if err != nil { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) return } // Pretty-print the response data. fmt.Println(resp) }
func ExampleAutoScaling_SetDesiredCapacity() { svc := autoscaling.New(nil) params := &autoscaling.SetDesiredCapacityInput{ AutoScalingGroupName: aws.String("ResourceName"), // Required DesiredCapacity: aws.Int64(1), // Required HonorCooldown: aws.Bool(true), } resp, err := svc.SetDesiredCapacity(params) if err != nil { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) return } // Pretty-print the response data. fmt.Println(resp) }
func ExampleAutoScaling_ExecutePolicy() { svc := autoscaling.New(nil) params := &autoscaling.ExecutePolicyInput{ PolicyName: aws.String("ResourceName"), // Required AutoScalingGroupName: aws.String("ResourceName"), BreachThreshold: aws.Float64(1.0), HonorCooldown: aws.Bool(true), MetricValue: aws.Float64(1.0), } resp, err := svc.ExecutePolicy(params) if err != nil { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) return } // Pretty-print the response data. fmt.Println(resp) }
func ExampleAutoScaling_EnterStandby() { svc := autoscaling.New(nil) params := &autoscaling.EnterStandbyInput{ AutoScalingGroupName: aws.String("ResourceName"), // Required ShouldDecrementDesiredCapacity: aws.Bool(true), // Required InstanceIds: []*string{ aws.String("XmlStringMaxLen16"), // Required // More values... }, } resp, err := svc.EnterStandby(params) if err != nil { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) return } // Pretty-print the response data. fmt.Println(resp) }
} return } } if r.HTTPResponse == nil { // Add a dummy request response object to ensure the HTTPResponse // value is consistent. r.HTTPResponse = &http.Response{ StatusCode: int(0), Status: http.StatusText(int(0)), Body: ioutil.NopCloser(bytes.NewReader([]byte{})), } } // Catch all other request errors. r.Error = awserr.New("RequestError", "send request failed", err) r.Retryable = aws.Bool(true) // network errors are retryable } }} // ValidateResponseHandler is a request handler to validate service response. var ValidateResponseHandler = request.NamedHandler{"core.ValidateResponseHandler", func(r *request.Request) { if r.HTTPResponse.StatusCode == 0 || r.HTTPResponse.StatusCode >= 300 { // this may be replaced by an UnmarshalError handler r.Error = awserr.New("UnknownError", "unknown error", nil) } }} // AfterRetryHandler performs final checks to determine if the request should // be retried and how long to delay. var AfterRetryHandler = request.NamedHandler{"core.AfterRetryHandler", func(r *request.Request) { // If one of the other handlers already set the retry state