github.com/aavshr/aws-sdk-go@v1.41.3/service/pricing/examples_test.go (about)

     1  // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
     2  
     3  package pricing_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/pricing"
    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 retrieve a list of services and service codes
    29  //
    30  // Retrieves the service for the given Service Code.
    31  func ExamplePricing_DescribeServices_shared00() {
    32  	svc := pricing.New(session.New())
    33  	input := &pricing.DescribeServicesInput{
    34  		FormatVersion: aws.String("aws_v1"),
    35  		MaxResults:    aws.Int64(1),
    36  		ServiceCode:   aws.String("AmazonEC2"),
    37  	}
    38  
    39  	result, err := svc.DescribeServices(input)
    40  	if err != nil {
    41  		if aerr, ok := err.(awserr.Error); ok {
    42  			switch aerr.Code() {
    43  			case pricing.ErrCodeInternalErrorException:
    44  				fmt.Println(pricing.ErrCodeInternalErrorException, aerr.Error())
    45  			case pricing.ErrCodeInvalidParameterException:
    46  				fmt.Println(pricing.ErrCodeInvalidParameterException, aerr.Error())
    47  			case pricing.ErrCodeNotFoundException:
    48  				fmt.Println(pricing.ErrCodeNotFoundException, aerr.Error())
    49  			case pricing.ErrCodeInvalidNextTokenException:
    50  				fmt.Println(pricing.ErrCodeInvalidNextTokenException, aerr.Error())
    51  			case pricing.ErrCodeExpiredNextTokenException:
    52  				fmt.Println(pricing.ErrCodeExpiredNextTokenException, aerr.Error())
    53  			default:
    54  				fmt.Println(aerr.Error())
    55  			}
    56  		} else {
    57  			// Print the error, cast err to awserr.Error to get the Code and
    58  			// Message from an error.
    59  			fmt.Println(err.Error())
    60  		}
    61  		return
    62  	}
    63  
    64  	fmt.Println(result)
    65  }
    66  
    67  // To retrieve a list of attribute values
    68  //
    69  // This operation returns a list of values available for the given attribute.
    70  func ExamplePricing_GetAttributeValues_shared00() {
    71  	svc := pricing.New(session.New())
    72  	input := &pricing.GetAttributeValuesInput{
    73  		AttributeName: aws.String("volumeType"),
    74  		MaxResults:    aws.Int64(2),
    75  		ServiceCode:   aws.String("AmazonEC2"),
    76  	}
    77  
    78  	result, err := svc.GetAttributeValues(input)
    79  	if err != nil {
    80  		if aerr, ok := err.(awserr.Error); ok {
    81  			switch aerr.Code() {
    82  			case pricing.ErrCodeInternalErrorException:
    83  				fmt.Println(pricing.ErrCodeInternalErrorException, aerr.Error())
    84  			case pricing.ErrCodeInvalidParameterException:
    85  				fmt.Println(pricing.ErrCodeInvalidParameterException, aerr.Error())
    86  			case pricing.ErrCodeNotFoundException:
    87  				fmt.Println(pricing.ErrCodeNotFoundException, aerr.Error())
    88  			case pricing.ErrCodeInvalidNextTokenException:
    89  				fmt.Println(pricing.ErrCodeInvalidNextTokenException, aerr.Error())
    90  			case pricing.ErrCodeExpiredNextTokenException:
    91  				fmt.Println(pricing.ErrCodeExpiredNextTokenException, aerr.Error())
    92  			default:
    93  				fmt.Println(aerr.Error())
    94  			}
    95  		} else {
    96  			// Print the error, cast err to awserr.Error to get the Code and
    97  			// Message from an error.
    98  			fmt.Println(err.Error())
    99  		}
   100  		return
   101  	}
   102  
   103  	fmt.Println(result)
   104  }