examples_test.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
  2. package eks_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/eks"
  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 create a new cluster
  23. //
  24. // The following example creates an Amazon EKS cluster called prod.
  25. func ExampleEKS_CreateCluster_shared00() {
  26. svc := eks.New(session.New())
  27. input := &eks.CreateClusterInput{
  28. ClientRequestToken: aws.String("1d2129a1-3d38-460a-9756-e5b91fddb951"),
  29. Name: aws.String("prod"),
  30. ResourcesVpcConfig: &eks.VpcConfigRequest{
  31. SecurityGroupIds: []*string{
  32. aws.String("sg-6979fe18"),
  33. },
  34. SubnetIds: []*string{
  35. aws.String("subnet-6782e71e"),
  36. aws.String("subnet-e7e761ac"),
  37. },
  38. },
  39. RoleArn: aws.String("arn:aws:iam::012345678910:role/eks-service-role-AWSServiceRoleForAmazonEKS-J7ONKE3BQ4PI"),
  40. Version: aws.String("1.10"),
  41. }
  42. result, err := svc.CreateCluster(input)
  43. if err != nil {
  44. if aerr, ok := err.(awserr.Error); ok {
  45. switch aerr.Code() {
  46. case eks.ErrCodeResourceInUseException:
  47. fmt.Println(eks.ErrCodeResourceInUseException, aerr.Error())
  48. case eks.ErrCodeResourceLimitExceededException:
  49. fmt.Println(eks.ErrCodeResourceLimitExceededException, aerr.Error())
  50. case eks.ErrCodeInvalidParameterException:
  51. fmt.Println(eks.ErrCodeInvalidParameterException, aerr.Error())
  52. case eks.ErrCodeClientException:
  53. fmt.Println(eks.ErrCodeClientException, aerr.Error())
  54. case eks.ErrCodeServerException:
  55. fmt.Println(eks.ErrCodeServerException, aerr.Error())
  56. case eks.ErrCodeServiceUnavailableException:
  57. fmt.Println(eks.ErrCodeServiceUnavailableException, aerr.Error())
  58. case eks.ErrCodeUnsupportedAvailabilityZoneException:
  59. fmt.Println(eks.ErrCodeUnsupportedAvailabilityZoneException, aerr.Error())
  60. default:
  61. fmt.Println(aerr.Error())
  62. }
  63. } else {
  64. // Print the error, cast err to awserr.Error to get the Code and
  65. // Message from an error.
  66. fmt.Println(err.Error())
  67. }
  68. return
  69. }
  70. fmt.Println(result)
  71. }
  72. // To delete a cluster
  73. //
  74. // This example command deletes a cluster named `devel` in your default region.
  75. func ExampleEKS_DeleteCluster_shared00() {
  76. svc := eks.New(session.New())
  77. input := &eks.DeleteClusterInput{
  78. Name: aws.String("devel"),
  79. }
  80. result, err := svc.DeleteCluster(input)
  81. if err != nil {
  82. if aerr, ok := err.(awserr.Error); ok {
  83. switch aerr.Code() {
  84. case eks.ErrCodeResourceInUseException:
  85. fmt.Println(eks.ErrCodeResourceInUseException, aerr.Error())
  86. case eks.ErrCodeResourceNotFoundException:
  87. fmt.Println(eks.ErrCodeResourceNotFoundException, aerr.Error())
  88. case eks.ErrCodeClientException:
  89. fmt.Println(eks.ErrCodeClientException, aerr.Error())
  90. case eks.ErrCodeServerException:
  91. fmt.Println(eks.ErrCodeServerException, aerr.Error())
  92. case eks.ErrCodeServiceUnavailableException:
  93. fmt.Println(eks.ErrCodeServiceUnavailableException, aerr.Error())
  94. default:
  95. fmt.Println(aerr.Error())
  96. }
  97. } else {
  98. // Print the error, cast err to awserr.Error to get the Code and
  99. // Message from an error.
  100. fmt.Println(err.Error())
  101. }
  102. return
  103. }
  104. fmt.Println(result)
  105. }
  106. // To describe a cluster
  107. //
  108. // This example command provides a description of the specified cluster in your default
  109. // region.
  110. func ExampleEKS_DescribeCluster_shared00() {
  111. svc := eks.New(session.New())
  112. input := &eks.DescribeClusterInput{
  113. Name: aws.String("devel"),
  114. }
  115. result, err := svc.DescribeCluster(input)
  116. if err != nil {
  117. if aerr, ok := err.(awserr.Error); ok {
  118. switch aerr.Code() {
  119. case eks.ErrCodeResourceNotFoundException:
  120. fmt.Println(eks.ErrCodeResourceNotFoundException, aerr.Error())
  121. case eks.ErrCodeClientException:
  122. fmt.Println(eks.ErrCodeClientException, aerr.Error())
  123. case eks.ErrCodeServerException:
  124. fmt.Println(eks.ErrCodeServerException, aerr.Error())
  125. case eks.ErrCodeServiceUnavailableException:
  126. fmt.Println(eks.ErrCodeServiceUnavailableException, aerr.Error())
  127. default:
  128. fmt.Println(aerr.Error())
  129. }
  130. } else {
  131. // Print the error, cast err to awserr.Error to get the Code and
  132. // Message from an error.
  133. fmt.Println(err.Error())
  134. }
  135. return
  136. }
  137. fmt.Println(result)
  138. }
  139. // To list your available clusters
  140. //
  141. // This example command lists all of your available clusters in your default region.
  142. func ExampleEKS_ListClusters_shared00() {
  143. svc := eks.New(session.New())
  144. input := &eks.ListClustersInput{}
  145. result, err := svc.ListClusters(input)
  146. if err != nil {
  147. if aerr, ok := err.(awserr.Error); ok {
  148. switch aerr.Code() {
  149. case eks.ErrCodeInvalidParameterException:
  150. fmt.Println(eks.ErrCodeInvalidParameterException, aerr.Error())
  151. case eks.ErrCodeClientException:
  152. fmt.Println(eks.ErrCodeClientException, aerr.Error())
  153. case eks.ErrCodeServerException:
  154. fmt.Println(eks.ErrCodeServerException, aerr.Error())
  155. case eks.ErrCodeServiceUnavailableException:
  156. fmt.Println(eks.ErrCodeServiceUnavailableException, aerr.Error())
  157. default:
  158. fmt.Println(aerr.Error())
  159. }
  160. } else {
  161. // Print the error, cast err to awserr.Error to get the Code and
  162. // Message from an error.
  163. fmt.Println(err.Error())
  164. }
  165. return
  166. }
  167. fmt.Println(result)
  168. }