examples_test.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
  2. package pricing_test
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "github.com/aws/aws-sdk-go/aws"
  8. "github.com/aws/aws-sdk-go/aws/awserr"
  9. "github.com/aws/aws-sdk-go/aws/session"
  10. "github.com/aws/aws-sdk-go/service/pricing"
  11. )
  12. var _ time.Duration
  13. var _ strings.Reader
  14. var _ aws.Config
  15. func parseTime(layout, value string) *time.Time {
  16. t, err := time.Parse(layout, value)
  17. if err != nil {
  18. panic(err)
  19. }
  20. return &t
  21. }
  22. // To retrieve a list of services and service codes
  23. //
  24. func ExamplePricing_DescribeServices_shared00() {
  25. svc := pricing.New(session.New())
  26. input := &pricing.DescribeServicesInput{
  27. FormatVersion: aws.String("aws_v1"),
  28. MaxResults: aws.Int64(1),
  29. ServiceCode: aws.String("AmazonEC2"),
  30. }
  31. result, err := svc.DescribeServices(input)
  32. if err != nil {
  33. if aerr, ok := err.(awserr.Error); ok {
  34. switch aerr.Code() {
  35. case pricing.ErrCodeInternalErrorException:
  36. fmt.Println(pricing.ErrCodeInternalErrorException, aerr.Error())
  37. case pricing.ErrCodeInvalidParameterException:
  38. fmt.Println(pricing.ErrCodeInvalidParameterException, aerr.Error())
  39. case pricing.ErrCodeNotFoundException:
  40. fmt.Println(pricing.ErrCodeNotFoundException, aerr.Error())
  41. case pricing.ErrCodeInvalidNextTokenException:
  42. fmt.Println(pricing.ErrCodeInvalidNextTokenException, aerr.Error())
  43. case pricing.ErrCodeExpiredNextTokenException:
  44. fmt.Println(pricing.ErrCodeExpiredNextTokenException, 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. fmt.Println(result)
  56. }
  57. // To retrieve a list of attribute values
  58. //
  59. // This operation returns a list of values available for the given attribute.
  60. func ExamplePricing_GetAttributeValues_shared00() {
  61. svc := pricing.New(session.New())
  62. input := &pricing.GetAttributeValuesInput{
  63. AttributeName: aws.String("volumeType"),
  64. MaxResults: aws.Int64(2),
  65. ServiceCode: aws.String("AmazonEC2"),
  66. }
  67. result, err := svc.GetAttributeValues(input)
  68. if err != nil {
  69. if aerr, ok := err.(awserr.Error); ok {
  70. switch aerr.Code() {
  71. case pricing.ErrCodeInternalErrorException:
  72. fmt.Println(pricing.ErrCodeInternalErrorException, aerr.Error())
  73. case pricing.ErrCodeInvalidParameterException:
  74. fmt.Println(pricing.ErrCodeInvalidParameterException, aerr.Error())
  75. case pricing.ErrCodeNotFoundException:
  76. fmt.Println(pricing.ErrCodeNotFoundException, aerr.Error())
  77. case pricing.ErrCodeInvalidNextTokenException:
  78. fmt.Println(pricing.ErrCodeInvalidNextTokenException, aerr.Error())
  79. case pricing.ErrCodeExpiredNextTokenException:
  80. fmt.Println(pricing.ErrCodeExpiredNextTokenException, aerr.Error())
  81. default:
  82. fmt.Println(aerr.Error())
  83. }
  84. } else {
  85. // Print the error, cast err to awserr.Error to get the Code and
  86. // Message from an error.
  87. fmt.Println(err.Error())
  88. }
  89. return
  90. }
  91. fmt.Println(result)
  92. }
  93. // To retrieve a list of products
  94. //
  95. // This operation returns a list of products that match the given criteria.
  96. func ExamplePricing_GetProducts_shared00() {
  97. svc := pricing.New(session.New())
  98. input := &pricing.GetProductsInput{
  99. Filters: []*pricing.Filter{
  100. {
  101. Field: aws.String("ServiceCode"),
  102. Type: aws.String("TERM_MATCH"),
  103. Value: aws.String("AmazonEC2"),
  104. },
  105. {
  106. Field: aws.String("volumeType"),
  107. Type: aws.String("TERM_MATCH"),
  108. Value: aws.String("Provisioned IOPS"),
  109. },
  110. },
  111. FormatVersion: aws.String("aws_v1"),
  112. MaxResults: aws.Int64(1),
  113. }
  114. result, err := svc.GetProducts(input)
  115. if err != nil {
  116. if aerr, ok := err.(awserr.Error); ok {
  117. switch aerr.Code() {
  118. case pricing.ErrCodeInternalErrorException:
  119. fmt.Println(pricing.ErrCodeInternalErrorException, aerr.Error())
  120. case pricing.ErrCodeInvalidParameterException:
  121. fmt.Println(pricing.ErrCodeInvalidParameterException, aerr.Error())
  122. case pricing.ErrCodeNotFoundException:
  123. fmt.Println(pricing.ErrCodeNotFoundException, aerr.Error())
  124. case pricing.ErrCodeInvalidNextTokenException:
  125. fmt.Println(pricing.ErrCodeInvalidNextTokenException, aerr.Error())
  126. case pricing.ErrCodeExpiredNextTokenException:
  127. fmt.Println(pricing.ErrCodeExpiredNextTokenException, aerr.Error())
  128. default:
  129. fmt.Println(aerr.Error())
  130. }
  131. } else {
  132. // Print the error, cast err to awserr.Error to get the Code and
  133. // Message from an error.
  134. fmt.Println(err.Error())
  135. }
  136. return
  137. }
  138. fmt.Println(result)
  139. }