github.com/aavshr/aws-sdk-go@v1.41.3/service/costandusagereportservice/examples_test.go (about) 1 // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 3 package costandusagereportservice_test 4 5 import ( 6 "fmt" 7 "strings" 8 "time" 9 10 "github.com/aavshr/aws-sdk-go/aws" 11 "github.com/aavshr/aws-sdk-go/aws/awserr" 12 "github.com/aavshr/aws-sdk-go/aws/session" 13 "github.com/aavshr/aws-sdk-go/service/costandusagereportservice" 14 ) 15 16 var _ time.Duration 17 var _ strings.Reader 18 var _ aws.Config 19 20 func parseTime(layout, value string) *time.Time { 21 t, err := time.Parse(layout, value) 22 if err != nil { 23 panic(err) 24 } 25 return &t 26 } 27 28 // To delete the AWS Cost and Usage report named ExampleReport. 29 // 30 // The following example deletes the AWS Cost and Usage report named ExampleReport. 31 func ExampleCostandUsageReportService_DeleteReportDefinition_shared00() { 32 svc := costandusagereportservice.New(session.New()) 33 input := &costandusagereportservice.DeleteReportDefinitionInput{ 34 ReportName: aws.String("ExampleReport"), 35 } 36 37 result, err := svc.DeleteReportDefinition(input) 38 if err != nil { 39 if aerr, ok := err.(awserr.Error); ok { 40 switch aerr.Code() { 41 case costandusagereportservice.ErrCodeInternalErrorException: 42 fmt.Println(costandusagereportservice.ErrCodeInternalErrorException, aerr.Error()) 43 case costandusagereportservice.ErrCodeValidationException: 44 fmt.Println(costandusagereportservice.ErrCodeValidationException, aerr.Error()) 45 default: 46 fmt.Println(aerr.Error()) 47 } 48 } else { 49 // Print the error, cast err to awserr.Error to get the Code and 50 // Message from an error. 51 fmt.Println(err.Error()) 52 } 53 return 54 } 55 56 fmt.Println(result) 57 } 58 59 // To list the AWS Cost and Usage reports for the account. 60 // 61 // The following example lists the AWS Cost and Usage reports for the account. 62 func ExampleCostandUsageReportService_DescribeReportDefinitions_shared00() { 63 svc := costandusagereportservice.New(session.New()) 64 input := &costandusagereportservice.DescribeReportDefinitionsInput{ 65 MaxResults: aws.Int64(5), 66 } 67 68 result, err := svc.DescribeReportDefinitions(input) 69 if err != nil { 70 if aerr, ok := err.(awserr.Error); ok { 71 switch aerr.Code() { 72 case costandusagereportservice.ErrCodeInternalErrorException: 73 fmt.Println(costandusagereportservice.ErrCodeInternalErrorException, aerr.Error()) 74 default: 75 fmt.Println(aerr.Error()) 76 } 77 } else { 78 // Print the error, cast err to awserr.Error to get the Code and 79 // Message from an error. 80 fmt.Println(err.Error()) 81 } 82 return 83 } 84 85 fmt.Println(result) 86 } 87 88 // To create a report named ExampleReport. 89 // 90 // The following example creates a AWS Cost and Usage report named ExampleReport. 91 func ExampleCostandUsageReportService_PutReportDefinition_shared00() { 92 svc := costandusagereportservice.New(session.New()) 93 input := &costandusagereportservice.PutReportDefinitionInput{ 94 ReportDefinition: &costandusagereportservice.ReportDefinition{ 95 AdditionalArtifacts: []*string{ 96 aws.String("REDSHIFT"), 97 aws.String("QUICKSIGHT"), 98 }, 99 AdditionalSchemaElements: []*string{ 100 aws.String("RESOURCES"), 101 }, 102 Compression: aws.String("ZIP"), 103 Format: aws.String("textORcsv"), 104 ReportName: aws.String("ExampleReport"), 105 S3Bucket: aws.String("example-s3-bucket"), 106 S3Prefix: aws.String("exampleprefix"), 107 S3Region: aws.String("us-east-1"), 108 TimeUnit: aws.String("DAILY"), 109 }, 110 } 111 112 result, err := svc.PutReportDefinition(input) 113 if err != nil { 114 if aerr, ok := err.(awserr.Error); ok { 115 switch aerr.Code() { 116 case costandusagereportservice.ErrCodeDuplicateReportNameException: 117 fmt.Println(costandusagereportservice.ErrCodeDuplicateReportNameException, aerr.Error()) 118 case costandusagereportservice.ErrCodeReportLimitReachedException: 119 fmt.Println(costandusagereportservice.ErrCodeReportLimitReachedException, aerr.Error()) 120 case costandusagereportservice.ErrCodeInternalErrorException: 121 fmt.Println(costandusagereportservice.ErrCodeInternalErrorException, aerr.Error()) 122 case costandusagereportservice.ErrCodeValidationException: 123 fmt.Println(costandusagereportservice.ErrCodeValidationException, aerr.Error()) 124 default: 125 fmt.Println(aerr.Error()) 126 } 127 } else { 128 // Print the error, cast err to awserr.Error to get the Code and 129 // Message from an error. 130 fmt.Println(err.Error()) 131 } 132 return 133 } 134 135 fmt.Println(result) 136 }