github.com/aavshr/aws-sdk-go@v1.41.3/service/eks/examples_test.go (about) 1 // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 3 package eks_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/eks" 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 create a new cluster 29 // 30 // The following example creates an Amazon EKS cluster called prod. 31 func ExampleEKS_CreateCluster_shared00() { 32 svc := eks.New(session.New()) 33 input := &eks.CreateClusterInput{ 34 ClientRequestToken: aws.String("1d2129a1-3d38-460a-9756-e5b91fddb951"), 35 Name: aws.String("prod"), 36 ResourcesVpcConfig: &eks.VpcConfigRequest{ 37 SecurityGroupIds: []*string{ 38 aws.String("sg-6979fe18"), 39 }, 40 SubnetIds: []*string{ 41 aws.String("subnet-6782e71e"), 42 aws.String("subnet-e7e761ac"), 43 }, 44 }, 45 RoleArn: aws.String("arn:aws:iam::012345678910:role/eks-service-role-AWSServiceRoleForAmazonEKS-J7ONKE3BQ4PI"), 46 Version: aws.String("1.10"), 47 } 48 49 result, err := svc.CreateCluster(input) 50 if err != nil { 51 if aerr, ok := err.(awserr.Error); ok { 52 switch aerr.Code() { 53 case eks.ErrCodeResourceInUseException: 54 fmt.Println(eks.ErrCodeResourceInUseException, aerr.Error()) 55 case eks.ErrCodeResourceLimitExceededException: 56 fmt.Println(eks.ErrCodeResourceLimitExceededException, aerr.Error()) 57 case eks.ErrCodeInvalidParameterException: 58 fmt.Println(eks.ErrCodeInvalidParameterException, aerr.Error()) 59 case eks.ErrCodeClientException: 60 fmt.Println(eks.ErrCodeClientException, aerr.Error()) 61 case eks.ErrCodeServerException: 62 fmt.Println(eks.ErrCodeServerException, aerr.Error()) 63 case eks.ErrCodeServiceUnavailableException: 64 fmt.Println(eks.ErrCodeServiceUnavailableException, aerr.Error()) 65 case eks.ErrCodeUnsupportedAvailabilityZoneException: 66 fmt.Println(eks.ErrCodeUnsupportedAvailabilityZoneException, aerr.Error()) 67 default: 68 fmt.Println(aerr.Error()) 69 } 70 } else { 71 // Print the error, cast err to awserr.Error to get the Code and 72 // Message from an error. 73 fmt.Println(err.Error()) 74 } 75 return 76 } 77 78 fmt.Println(result) 79 } 80 81 // To delete a cluster 82 // 83 // This example command deletes a cluster named `devel` in your default region. 84 func ExampleEKS_DeleteCluster_shared00() { 85 svc := eks.New(session.New()) 86 input := &eks.DeleteClusterInput{ 87 Name: aws.String("devel"), 88 } 89 90 result, err := svc.DeleteCluster(input) 91 if err != nil { 92 if aerr, ok := err.(awserr.Error); ok { 93 switch aerr.Code() { 94 case eks.ErrCodeResourceInUseException: 95 fmt.Println(eks.ErrCodeResourceInUseException, aerr.Error()) 96 case eks.ErrCodeResourceNotFoundException: 97 fmt.Println(eks.ErrCodeResourceNotFoundException, aerr.Error()) 98 case eks.ErrCodeClientException: 99 fmt.Println(eks.ErrCodeClientException, aerr.Error()) 100 case eks.ErrCodeServerException: 101 fmt.Println(eks.ErrCodeServerException, aerr.Error()) 102 case eks.ErrCodeServiceUnavailableException: 103 fmt.Println(eks.ErrCodeServiceUnavailableException, aerr.Error()) 104 default: 105 fmt.Println(aerr.Error()) 106 } 107 } else { 108 // Print the error, cast err to awserr.Error to get the Code and 109 // Message from an error. 110 fmt.Println(err.Error()) 111 } 112 return 113 } 114 115 fmt.Println(result) 116 } 117 118 // To describe a cluster 119 // 120 // This example command provides a description of the specified cluster in your default 121 // region. 122 func ExampleEKS_DescribeCluster_shared00() { 123 svc := eks.New(session.New()) 124 input := &eks.DescribeClusterInput{ 125 Name: aws.String("devel"), 126 } 127 128 result, err := svc.DescribeCluster(input) 129 if err != nil { 130 if aerr, ok := err.(awserr.Error); ok { 131 switch aerr.Code() { 132 case eks.ErrCodeResourceNotFoundException: 133 fmt.Println(eks.ErrCodeResourceNotFoundException, aerr.Error()) 134 case eks.ErrCodeClientException: 135 fmt.Println(eks.ErrCodeClientException, aerr.Error()) 136 case eks.ErrCodeServerException: 137 fmt.Println(eks.ErrCodeServerException, aerr.Error()) 138 case eks.ErrCodeServiceUnavailableException: 139 fmt.Println(eks.ErrCodeServiceUnavailableException, aerr.Error()) 140 default: 141 fmt.Println(aerr.Error()) 142 } 143 } else { 144 // Print the error, cast err to awserr.Error to get the Code and 145 // Message from an error. 146 fmt.Println(err.Error()) 147 } 148 return 149 } 150 151 fmt.Println(result) 152 } 153 154 // To list your available clusters 155 // 156 // This example command lists all of your available clusters in your default region. 157 func ExampleEKS_ListClusters_shared00() { 158 svc := eks.New(session.New()) 159 input := &eks.ListClustersInput{} 160 161 result, err := svc.ListClusters(input) 162 if err != nil { 163 if aerr, ok := err.(awserr.Error); ok { 164 switch aerr.Code() { 165 case eks.ErrCodeInvalidParameterException: 166 fmt.Println(eks.ErrCodeInvalidParameterException, aerr.Error()) 167 case eks.ErrCodeClientException: 168 fmt.Println(eks.ErrCodeClientException, aerr.Error()) 169 case eks.ErrCodeServerException: 170 fmt.Println(eks.ErrCodeServerException, aerr.Error()) 171 case eks.ErrCodeServiceUnavailableException: 172 fmt.Println(eks.ErrCodeServiceUnavailableException, aerr.Error()) 173 default: 174 fmt.Println(aerr.Error()) 175 } 176 } else { 177 // Print the error, cast err to awserr.Error to get the Code and 178 // Message from an error. 179 fmt.Println(err.Error()) 180 } 181 return 182 } 183 184 fmt.Println(result) 185 } 186 187 // To list tags for a cluster 188 // 189 // This example lists all of the tags for the `beta` cluster. 190 func ExampleEKS_ListTagsForResource_shared00() { 191 svc := eks.New(session.New()) 192 input := &eks.ListTagsForResourceInput{ 193 ResourceArn: aws.String("arn:aws:eks:us-west-2:012345678910:cluster/beta"), 194 } 195 196 result, err := svc.ListTagsForResource(input) 197 if err != nil { 198 if aerr, ok := err.(awserr.Error); ok { 199 switch aerr.Code() { 200 case eks.ErrCodeBadRequestException: 201 fmt.Println(eks.ErrCodeBadRequestException, aerr.Error()) 202 case eks.ErrCodeNotFoundException: 203 fmt.Println(eks.ErrCodeNotFoundException, aerr.Error()) 204 default: 205 fmt.Println(aerr.Error()) 206 } 207 } else { 208 // Print the error, cast err to awserr.Error to get the Code and 209 // Message from an error. 210 fmt.Println(err.Error()) 211 } 212 return 213 } 214 215 fmt.Println(result) 216 }