1// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 3package elbv2_test 4 5import ( 6 "fmt" 7 "strings" 8 "time" 9 10 "github.com/aws/aws-sdk-go/aws" 11 "github.com/aws/aws-sdk-go/aws/awserr" 12 "github.com/aws/aws-sdk-go/aws/session" 13 "github.com/aws/aws-sdk-go/service/elbv2" 14) 15 16var _ time.Duration 17var _ strings.Reader 18var _ aws.Config 19 20func 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 add tags to a load balancer 29// 30// This example adds the specified tags to the specified load balancer. 31func ExampleELBV2_AddTags_shared00() { 32 svc := elbv2.New(session.New()) 33 input := &elbv2.AddTagsInput{ 34 ResourceArns: []*string{ 35 aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"), 36 }, 37 Tags: []*elbv2.Tag{ 38 { 39 Key: aws.String("project"), 40 Value: aws.String("lima"), 41 }, 42 { 43 Key: aws.String("department"), 44 Value: aws.String("digital-media"), 45 }, 46 }, 47 } 48 49 result, err := svc.AddTags(input) 50 if err != nil { 51 if aerr, ok := err.(awserr.Error); ok { 52 switch aerr.Code() { 53 case elbv2.ErrCodeDuplicateTagKeysException: 54 fmt.Println(elbv2.ErrCodeDuplicateTagKeysException, aerr.Error()) 55 case elbv2.ErrCodeTooManyTagsException: 56 fmt.Println(elbv2.ErrCodeTooManyTagsException, aerr.Error()) 57 case elbv2.ErrCodeLoadBalancerNotFoundException: 58 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 59 case elbv2.ErrCodeTargetGroupNotFoundException: 60 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 61 default: 62 fmt.Println(aerr.Error()) 63 } 64 } else { 65 // Print the error, cast err to awserr.Error to get the Code and 66 // Message from an error. 67 fmt.Println(err.Error()) 68 } 69 return 70 } 71 72 fmt.Println(result) 73} 74 75// To create an HTTP listener 76// 77// This example creates an HTTP listener for the specified load balancer that forwards 78// requests to the specified target group. 79func ExampleELBV2_CreateListener_shared00() { 80 svc := elbv2.New(session.New()) 81 input := &elbv2.CreateListenerInput{ 82 DefaultActions: []*elbv2.Action{ 83 { 84 TargetGroupArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"), 85 Type: aws.String("forward"), 86 }, 87 }, 88 LoadBalancerArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"), 89 Port: aws.Int64(80), 90 Protocol: aws.String("HTTP"), 91 } 92 93 result, err := svc.CreateListener(input) 94 if err != nil { 95 if aerr, ok := err.(awserr.Error); ok { 96 switch aerr.Code() { 97 case elbv2.ErrCodeDuplicateListenerException: 98 fmt.Println(elbv2.ErrCodeDuplicateListenerException, aerr.Error()) 99 case elbv2.ErrCodeTooManyListenersException: 100 fmt.Println(elbv2.ErrCodeTooManyListenersException, aerr.Error()) 101 case elbv2.ErrCodeTooManyCertificatesException: 102 fmt.Println(elbv2.ErrCodeTooManyCertificatesException, aerr.Error()) 103 case elbv2.ErrCodeLoadBalancerNotFoundException: 104 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 105 case elbv2.ErrCodeTargetGroupNotFoundException: 106 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 107 case elbv2.ErrCodeTargetGroupAssociationLimitException: 108 fmt.Println(elbv2.ErrCodeTargetGroupAssociationLimitException, aerr.Error()) 109 case elbv2.ErrCodeInvalidConfigurationRequestException: 110 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 111 case elbv2.ErrCodeIncompatibleProtocolsException: 112 fmt.Println(elbv2.ErrCodeIncompatibleProtocolsException, aerr.Error()) 113 case elbv2.ErrCodeSSLPolicyNotFoundException: 114 fmt.Println(elbv2.ErrCodeSSLPolicyNotFoundException, aerr.Error()) 115 case elbv2.ErrCodeCertificateNotFoundException: 116 fmt.Println(elbv2.ErrCodeCertificateNotFoundException, aerr.Error()) 117 case elbv2.ErrCodeUnsupportedProtocolException: 118 fmt.Println(elbv2.ErrCodeUnsupportedProtocolException, aerr.Error()) 119 case elbv2.ErrCodeTooManyRegistrationsForTargetIdException: 120 fmt.Println(elbv2.ErrCodeTooManyRegistrationsForTargetIdException, aerr.Error()) 121 case elbv2.ErrCodeTooManyTargetsException: 122 fmt.Println(elbv2.ErrCodeTooManyTargetsException, aerr.Error()) 123 default: 124 fmt.Println(aerr.Error()) 125 } 126 } else { 127 // Print the error, cast err to awserr.Error to get the Code and 128 // Message from an error. 129 fmt.Println(err.Error()) 130 } 131 return 132 } 133 134 fmt.Println(result) 135} 136 137// To create an HTTPS listener 138// 139// This example creates an HTTPS listener for the specified load balancer that forwards 140// requests to the specified target group. Note that you must specify an SSL certificate 141// for an HTTPS listener. You can create and manage certificates using AWS Certificate 142// Manager (ACM). Alternatively, you can create a certificate using SSL/TLS tools, get 143// the certificate signed by a certificate authority (CA), and upload the certificate 144// to AWS Identity and Access Management (IAM). 145func ExampleELBV2_CreateListener_shared01() { 146 svc := elbv2.New(session.New()) 147 input := &elbv2.CreateListenerInput{ 148 Certificates: []*elbv2.Certificate{ 149 { 150 CertificateArn: aws.String("arn:aws:iam::123456789012:server-certificate/my-server-cert"), 151 }, 152 }, 153 DefaultActions: []*elbv2.Action{ 154 { 155 TargetGroupArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"), 156 Type: aws.String("forward"), 157 }, 158 }, 159 LoadBalancerArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"), 160 Port: aws.Int64(443), 161 Protocol: aws.String("HTTPS"), 162 SslPolicy: aws.String("ELBSecurityPolicy-2015-05"), 163 } 164 165 result, err := svc.CreateListener(input) 166 if err != nil { 167 if aerr, ok := err.(awserr.Error); ok { 168 switch aerr.Code() { 169 case elbv2.ErrCodeDuplicateListenerException: 170 fmt.Println(elbv2.ErrCodeDuplicateListenerException, aerr.Error()) 171 case elbv2.ErrCodeTooManyListenersException: 172 fmt.Println(elbv2.ErrCodeTooManyListenersException, aerr.Error()) 173 case elbv2.ErrCodeTooManyCertificatesException: 174 fmt.Println(elbv2.ErrCodeTooManyCertificatesException, aerr.Error()) 175 case elbv2.ErrCodeLoadBalancerNotFoundException: 176 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 177 case elbv2.ErrCodeTargetGroupNotFoundException: 178 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 179 case elbv2.ErrCodeTargetGroupAssociationLimitException: 180 fmt.Println(elbv2.ErrCodeTargetGroupAssociationLimitException, aerr.Error()) 181 case elbv2.ErrCodeInvalidConfigurationRequestException: 182 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 183 case elbv2.ErrCodeIncompatibleProtocolsException: 184 fmt.Println(elbv2.ErrCodeIncompatibleProtocolsException, aerr.Error()) 185 case elbv2.ErrCodeSSLPolicyNotFoundException: 186 fmt.Println(elbv2.ErrCodeSSLPolicyNotFoundException, aerr.Error()) 187 case elbv2.ErrCodeCertificateNotFoundException: 188 fmt.Println(elbv2.ErrCodeCertificateNotFoundException, aerr.Error()) 189 case elbv2.ErrCodeUnsupportedProtocolException: 190 fmt.Println(elbv2.ErrCodeUnsupportedProtocolException, aerr.Error()) 191 case elbv2.ErrCodeTooManyRegistrationsForTargetIdException: 192 fmt.Println(elbv2.ErrCodeTooManyRegistrationsForTargetIdException, aerr.Error()) 193 case elbv2.ErrCodeTooManyTargetsException: 194 fmt.Println(elbv2.ErrCodeTooManyTargetsException, aerr.Error()) 195 default: 196 fmt.Println(aerr.Error()) 197 } 198 } else { 199 // Print the error, cast err to awserr.Error to get the Code and 200 // Message from an error. 201 fmt.Println(err.Error()) 202 } 203 return 204 } 205 206 fmt.Println(result) 207} 208 209// To create an Internet-facing load balancer 210// 211// This example creates an Internet-facing load balancer and enables the Availability 212// Zones for the specified subnets. 213func ExampleELBV2_CreateLoadBalancer_shared00() { 214 svc := elbv2.New(session.New()) 215 input := &elbv2.CreateLoadBalancerInput{ 216 Name: aws.String("my-load-balancer"), 217 Subnets: []*string{ 218 aws.String("subnet-b7d581c0"), 219 aws.String("subnet-8360a9e7"), 220 }, 221 } 222 223 result, err := svc.CreateLoadBalancer(input) 224 if err != nil { 225 if aerr, ok := err.(awserr.Error); ok { 226 switch aerr.Code() { 227 case elbv2.ErrCodeDuplicateLoadBalancerNameException: 228 fmt.Println(elbv2.ErrCodeDuplicateLoadBalancerNameException, aerr.Error()) 229 case elbv2.ErrCodeTooManyLoadBalancersException: 230 fmt.Println(elbv2.ErrCodeTooManyLoadBalancersException, aerr.Error()) 231 case elbv2.ErrCodeInvalidConfigurationRequestException: 232 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 233 case elbv2.ErrCodeSubnetNotFoundException: 234 fmt.Println(elbv2.ErrCodeSubnetNotFoundException, aerr.Error()) 235 case elbv2.ErrCodeInvalidSubnetException: 236 fmt.Println(elbv2.ErrCodeInvalidSubnetException, aerr.Error()) 237 case elbv2.ErrCodeInvalidSecurityGroupException: 238 fmt.Println(elbv2.ErrCodeInvalidSecurityGroupException, aerr.Error()) 239 case elbv2.ErrCodeInvalidSchemeException: 240 fmt.Println(elbv2.ErrCodeInvalidSchemeException, aerr.Error()) 241 case elbv2.ErrCodeTooManyTagsException: 242 fmt.Println(elbv2.ErrCodeTooManyTagsException, aerr.Error()) 243 case elbv2.ErrCodeDuplicateTagKeysException: 244 fmt.Println(elbv2.ErrCodeDuplicateTagKeysException, aerr.Error()) 245 case elbv2.ErrCodeResourceInUseException: 246 fmt.Println(elbv2.ErrCodeResourceInUseException, aerr.Error()) 247 case elbv2.ErrCodeAllocationIdNotFoundException: 248 fmt.Println(elbv2.ErrCodeAllocationIdNotFoundException, aerr.Error()) 249 case elbv2.ErrCodeAvailabilityZoneNotSupportedException: 250 fmt.Println(elbv2.ErrCodeAvailabilityZoneNotSupportedException, aerr.Error()) 251 default: 252 fmt.Println(aerr.Error()) 253 } 254 } else { 255 // Print the error, cast err to awserr.Error to get the Code and 256 // Message from an error. 257 fmt.Println(err.Error()) 258 } 259 return 260 } 261 262 fmt.Println(result) 263} 264 265// To create an internal load balancer 266// 267// This example creates an internal load balancer and enables the Availability Zones 268// for the specified subnets. 269func ExampleELBV2_CreateLoadBalancer_shared01() { 270 svc := elbv2.New(session.New()) 271 input := &elbv2.CreateLoadBalancerInput{ 272 Name: aws.String("my-internal-load-balancer"), 273 Scheme: aws.String("internal"), 274 Subnets: []*string{ 275 aws.String("subnet-b7d581c0"), 276 aws.String("subnet-8360a9e7"), 277 }, 278 } 279 280 result, err := svc.CreateLoadBalancer(input) 281 if err != nil { 282 if aerr, ok := err.(awserr.Error); ok { 283 switch aerr.Code() { 284 case elbv2.ErrCodeDuplicateLoadBalancerNameException: 285 fmt.Println(elbv2.ErrCodeDuplicateLoadBalancerNameException, aerr.Error()) 286 case elbv2.ErrCodeTooManyLoadBalancersException: 287 fmt.Println(elbv2.ErrCodeTooManyLoadBalancersException, aerr.Error()) 288 case elbv2.ErrCodeInvalidConfigurationRequestException: 289 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 290 case elbv2.ErrCodeSubnetNotFoundException: 291 fmt.Println(elbv2.ErrCodeSubnetNotFoundException, aerr.Error()) 292 case elbv2.ErrCodeInvalidSubnetException: 293 fmt.Println(elbv2.ErrCodeInvalidSubnetException, aerr.Error()) 294 case elbv2.ErrCodeInvalidSecurityGroupException: 295 fmt.Println(elbv2.ErrCodeInvalidSecurityGroupException, aerr.Error()) 296 case elbv2.ErrCodeInvalidSchemeException: 297 fmt.Println(elbv2.ErrCodeInvalidSchemeException, aerr.Error()) 298 case elbv2.ErrCodeTooManyTagsException: 299 fmt.Println(elbv2.ErrCodeTooManyTagsException, aerr.Error()) 300 case elbv2.ErrCodeDuplicateTagKeysException: 301 fmt.Println(elbv2.ErrCodeDuplicateTagKeysException, aerr.Error()) 302 case elbv2.ErrCodeResourceInUseException: 303 fmt.Println(elbv2.ErrCodeResourceInUseException, aerr.Error()) 304 case elbv2.ErrCodeAllocationIdNotFoundException: 305 fmt.Println(elbv2.ErrCodeAllocationIdNotFoundException, aerr.Error()) 306 case elbv2.ErrCodeAvailabilityZoneNotSupportedException: 307 fmt.Println(elbv2.ErrCodeAvailabilityZoneNotSupportedException, aerr.Error()) 308 default: 309 fmt.Println(aerr.Error()) 310 } 311 } else { 312 // Print the error, cast err to awserr.Error to get the Code and 313 // Message from an error. 314 fmt.Println(err.Error()) 315 } 316 return 317 } 318 319 fmt.Println(result) 320} 321 322// To create a rule 323// 324// This example creates a rule that forwards requests to the specified target group 325// if the URL contains the specified pattern (for example, /img/*). 326func ExampleELBV2_CreateRule_shared00() { 327 svc := elbv2.New(session.New()) 328 input := &elbv2.CreateRuleInput{ 329 Actions: []*elbv2.Action{ 330 { 331 TargetGroupArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"), 332 Type: aws.String("forward"), 333 }, 334 }, 335 Conditions: []*elbv2.RuleCondition{ 336 { 337 Field: aws.String("path-pattern"), 338 Values: []*string{ 339 aws.String("/img/*"), 340 }, 341 }, 342 }, 343 ListenerArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2"), 344 Priority: aws.Int64(10), 345 } 346 347 result, err := svc.CreateRule(input) 348 if err != nil { 349 if aerr, ok := err.(awserr.Error); ok { 350 switch aerr.Code() { 351 case elbv2.ErrCodePriorityInUseException: 352 fmt.Println(elbv2.ErrCodePriorityInUseException, aerr.Error()) 353 case elbv2.ErrCodeTooManyTargetGroupsException: 354 fmt.Println(elbv2.ErrCodeTooManyTargetGroupsException, aerr.Error()) 355 case elbv2.ErrCodeTooManyRulesException: 356 fmt.Println(elbv2.ErrCodeTooManyRulesException, aerr.Error()) 357 case elbv2.ErrCodeTargetGroupAssociationLimitException: 358 fmt.Println(elbv2.ErrCodeTargetGroupAssociationLimitException, aerr.Error()) 359 case elbv2.ErrCodeIncompatibleProtocolsException: 360 fmt.Println(elbv2.ErrCodeIncompatibleProtocolsException, aerr.Error()) 361 case elbv2.ErrCodeListenerNotFoundException: 362 fmt.Println(elbv2.ErrCodeListenerNotFoundException, aerr.Error()) 363 case elbv2.ErrCodeTargetGroupNotFoundException: 364 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 365 case elbv2.ErrCodeInvalidConfigurationRequestException: 366 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 367 case elbv2.ErrCodeTooManyRegistrationsForTargetIdException: 368 fmt.Println(elbv2.ErrCodeTooManyRegistrationsForTargetIdException, aerr.Error()) 369 case elbv2.ErrCodeTooManyTargetsException: 370 fmt.Println(elbv2.ErrCodeTooManyTargetsException, aerr.Error()) 371 default: 372 fmt.Println(aerr.Error()) 373 } 374 } else { 375 // Print the error, cast err to awserr.Error to get the Code and 376 // Message from an error. 377 fmt.Println(err.Error()) 378 } 379 return 380 } 381 382 fmt.Println(result) 383} 384 385// To create a target group 386// 387// This example creates a target group that you can use to route traffic to targets 388// using HTTP on port 80. This target group uses the default health check configuration. 389func ExampleELBV2_CreateTargetGroup_shared00() { 390 svc := elbv2.New(session.New()) 391 input := &elbv2.CreateTargetGroupInput{ 392 Name: aws.String("my-targets"), 393 Port: aws.Int64(80), 394 Protocol: aws.String("HTTP"), 395 VpcId: aws.String("vpc-3ac0fb5f"), 396 } 397 398 result, err := svc.CreateTargetGroup(input) 399 if err != nil { 400 if aerr, ok := err.(awserr.Error); ok { 401 switch aerr.Code() { 402 case elbv2.ErrCodeDuplicateTargetGroupNameException: 403 fmt.Println(elbv2.ErrCodeDuplicateTargetGroupNameException, aerr.Error()) 404 case elbv2.ErrCodeTooManyTargetGroupsException: 405 fmt.Println(elbv2.ErrCodeTooManyTargetGroupsException, aerr.Error()) 406 case elbv2.ErrCodeInvalidConfigurationRequestException: 407 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 408 default: 409 fmt.Println(aerr.Error()) 410 } 411 } else { 412 // Print the error, cast err to awserr.Error to get the Code and 413 // Message from an error. 414 fmt.Println(err.Error()) 415 } 416 return 417 } 418 419 fmt.Println(result) 420} 421 422// To delete a listener 423// 424// This example deletes the specified listener. 425func ExampleELBV2_DeleteListener_shared00() { 426 svc := elbv2.New(session.New()) 427 input := &elbv2.DeleteListenerInput{ 428 ListenerArn: aws.String("arn:aws:elasticloadbalancing:ua-west-2:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2"), 429 } 430 431 result, err := svc.DeleteListener(input) 432 if err != nil { 433 if aerr, ok := err.(awserr.Error); ok { 434 switch aerr.Code() { 435 case elbv2.ErrCodeListenerNotFoundException: 436 fmt.Println(elbv2.ErrCodeListenerNotFoundException, aerr.Error()) 437 default: 438 fmt.Println(aerr.Error()) 439 } 440 } else { 441 // Print the error, cast err to awserr.Error to get the Code and 442 // Message from an error. 443 fmt.Println(err.Error()) 444 } 445 return 446 } 447 448 fmt.Println(result) 449} 450 451// To delete a load balancer 452// 453// This example deletes the specified load balancer. 454func ExampleELBV2_DeleteLoadBalancer_shared00() { 455 svc := elbv2.New(session.New()) 456 input := &elbv2.DeleteLoadBalancerInput{ 457 LoadBalancerArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"), 458 } 459 460 result, err := svc.DeleteLoadBalancer(input) 461 if err != nil { 462 if aerr, ok := err.(awserr.Error); ok { 463 switch aerr.Code() { 464 case elbv2.ErrCodeLoadBalancerNotFoundException: 465 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 466 case elbv2.ErrCodeOperationNotPermittedException: 467 fmt.Println(elbv2.ErrCodeOperationNotPermittedException, aerr.Error()) 468 default: 469 fmt.Println(aerr.Error()) 470 } 471 } else { 472 // Print the error, cast err to awserr.Error to get the Code and 473 // Message from an error. 474 fmt.Println(err.Error()) 475 } 476 return 477 } 478 479 fmt.Println(result) 480} 481 482// To delete a rule 483// 484// This example deletes the specified rule. 485func ExampleELBV2_DeleteRule_shared00() { 486 svc := elbv2.New(session.New()) 487 input := &elbv2.DeleteRuleInput{ 488 RuleArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:listener-rule/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2/1291d13826f405c3"), 489 } 490 491 result, err := svc.DeleteRule(input) 492 if err != nil { 493 if aerr, ok := err.(awserr.Error); ok { 494 switch aerr.Code() { 495 case elbv2.ErrCodeRuleNotFoundException: 496 fmt.Println(elbv2.ErrCodeRuleNotFoundException, aerr.Error()) 497 case elbv2.ErrCodeOperationNotPermittedException: 498 fmt.Println(elbv2.ErrCodeOperationNotPermittedException, aerr.Error()) 499 default: 500 fmt.Println(aerr.Error()) 501 } 502 } else { 503 // Print the error, cast err to awserr.Error to get the Code and 504 // Message from an error. 505 fmt.Println(err.Error()) 506 } 507 return 508 } 509 510 fmt.Println(result) 511} 512 513// To delete a target group 514// 515// This example deletes the specified target group. 516func ExampleELBV2_DeleteTargetGroup_shared00() { 517 svc := elbv2.New(session.New()) 518 input := &elbv2.DeleteTargetGroupInput{ 519 TargetGroupArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"), 520 } 521 522 result, err := svc.DeleteTargetGroup(input) 523 if err != nil { 524 if aerr, ok := err.(awserr.Error); ok { 525 switch aerr.Code() { 526 case elbv2.ErrCodeResourceInUseException: 527 fmt.Println(elbv2.ErrCodeResourceInUseException, aerr.Error()) 528 default: 529 fmt.Println(aerr.Error()) 530 } 531 } else { 532 // Print the error, cast err to awserr.Error to get the Code and 533 // Message from an error. 534 fmt.Println(err.Error()) 535 } 536 return 537 } 538 539 fmt.Println(result) 540} 541 542// To deregister a target from a target group 543// 544// This example deregisters the specified instance from the specified target group. 545func ExampleELBV2_DeregisterTargets_shared00() { 546 svc := elbv2.New(session.New()) 547 input := &elbv2.DeregisterTargetsInput{ 548 TargetGroupArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"), 549 Targets: []*elbv2.TargetDescription{ 550 { 551 Id: aws.String("i-0f76fade"), 552 }, 553 }, 554 } 555 556 result, err := svc.DeregisterTargets(input) 557 if err != nil { 558 if aerr, ok := err.(awserr.Error); ok { 559 switch aerr.Code() { 560 case elbv2.ErrCodeTargetGroupNotFoundException: 561 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 562 case elbv2.ErrCodeInvalidTargetException: 563 fmt.Println(elbv2.ErrCodeInvalidTargetException, aerr.Error()) 564 default: 565 fmt.Println(aerr.Error()) 566 } 567 } else { 568 // Print the error, cast err to awserr.Error to get the Code and 569 // Message from an error. 570 fmt.Println(err.Error()) 571 } 572 return 573 } 574 575 fmt.Println(result) 576} 577 578// To describe a listener 579// 580// This example describes the specified listener. 581func ExampleELBV2_DescribeListeners_shared00() { 582 svc := elbv2.New(session.New()) 583 input := &elbv2.DescribeListenersInput{ 584 ListenerArns: []*string{ 585 aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2"), 586 }, 587 } 588 589 result, err := svc.DescribeListeners(input) 590 if err != nil { 591 if aerr, ok := err.(awserr.Error); ok { 592 switch aerr.Code() { 593 case elbv2.ErrCodeListenerNotFoundException: 594 fmt.Println(elbv2.ErrCodeListenerNotFoundException, aerr.Error()) 595 case elbv2.ErrCodeLoadBalancerNotFoundException: 596 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 597 default: 598 fmt.Println(aerr.Error()) 599 } 600 } else { 601 // Print the error, cast err to awserr.Error to get the Code and 602 // Message from an error. 603 fmt.Println(err.Error()) 604 } 605 return 606 } 607 608 fmt.Println(result) 609} 610 611// To describe load balancer attributes 612// 613// This example describes the attributes of the specified load balancer. 614func ExampleELBV2_DescribeLoadBalancerAttributes_shared00() { 615 svc := elbv2.New(session.New()) 616 input := &elbv2.DescribeLoadBalancerAttributesInput{ 617 LoadBalancerArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"), 618 } 619 620 result, err := svc.DescribeLoadBalancerAttributes(input) 621 if err != nil { 622 if aerr, ok := err.(awserr.Error); ok { 623 switch aerr.Code() { 624 case elbv2.ErrCodeLoadBalancerNotFoundException: 625 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 626 default: 627 fmt.Println(aerr.Error()) 628 } 629 } else { 630 // Print the error, cast err to awserr.Error to get the Code and 631 // Message from an error. 632 fmt.Println(err.Error()) 633 } 634 return 635 } 636 637 fmt.Println(result) 638} 639 640// To describe a load balancer 641// 642// This example describes the specified load balancer. 643func ExampleELBV2_DescribeLoadBalancers_shared00() { 644 svc := elbv2.New(session.New()) 645 input := &elbv2.DescribeLoadBalancersInput{ 646 LoadBalancerArns: []*string{ 647 aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"), 648 }, 649 } 650 651 result, err := svc.DescribeLoadBalancers(input) 652 if err != nil { 653 if aerr, ok := err.(awserr.Error); ok { 654 switch aerr.Code() { 655 case elbv2.ErrCodeLoadBalancerNotFoundException: 656 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 657 default: 658 fmt.Println(aerr.Error()) 659 } 660 } else { 661 // Print the error, cast err to awserr.Error to get the Code and 662 // Message from an error. 663 fmt.Println(err.Error()) 664 } 665 return 666 } 667 668 fmt.Println(result) 669} 670 671// To describe a rule 672// 673// This example describes the specified rule. 674func ExampleELBV2_DescribeRules_shared00() { 675 svc := elbv2.New(session.New()) 676 input := &elbv2.DescribeRulesInput{ 677 RuleArns: []*string{ 678 aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:listener-rule/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2/9683b2d02a6cabee"), 679 }, 680 } 681 682 result, err := svc.DescribeRules(input) 683 if err != nil { 684 if aerr, ok := err.(awserr.Error); ok { 685 switch aerr.Code() { 686 case elbv2.ErrCodeListenerNotFoundException: 687 fmt.Println(elbv2.ErrCodeListenerNotFoundException, aerr.Error()) 688 case elbv2.ErrCodeRuleNotFoundException: 689 fmt.Println(elbv2.ErrCodeRuleNotFoundException, aerr.Error()) 690 default: 691 fmt.Println(aerr.Error()) 692 } 693 } else { 694 // Print the error, cast err to awserr.Error to get the Code and 695 // Message from an error. 696 fmt.Println(err.Error()) 697 } 698 return 699 } 700 701 fmt.Println(result) 702} 703 704// To describe a policy used for SSL negotiation 705// 706// This example describes the specified policy used for SSL negotiation. 707func ExampleELBV2_DescribeSSLPolicies_shared00() { 708 svc := elbv2.New(session.New()) 709 input := &elbv2.DescribeSSLPoliciesInput{ 710 Names: []*string{ 711 aws.String("ELBSecurityPolicy-2015-05"), 712 }, 713 } 714 715 result, err := svc.DescribeSSLPolicies(input) 716 if err != nil { 717 if aerr, ok := err.(awserr.Error); ok { 718 switch aerr.Code() { 719 case elbv2.ErrCodeSSLPolicyNotFoundException: 720 fmt.Println(elbv2.ErrCodeSSLPolicyNotFoundException, aerr.Error()) 721 default: 722 fmt.Println(aerr.Error()) 723 } 724 } else { 725 // Print the error, cast err to awserr.Error to get the Code and 726 // Message from an error. 727 fmt.Println(err.Error()) 728 } 729 return 730 } 731 732 fmt.Println(result) 733} 734 735// To describe the tags assigned to a load balancer 736// 737// This example describes the tags assigned to the specified load balancer. 738func ExampleELBV2_DescribeTags_shared00() { 739 svc := elbv2.New(session.New()) 740 input := &elbv2.DescribeTagsInput{ 741 ResourceArns: []*string{ 742 aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"), 743 }, 744 } 745 746 result, err := svc.DescribeTags(input) 747 if err != nil { 748 if aerr, ok := err.(awserr.Error); ok { 749 switch aerr.Code() { 750 case elbv2.ErrCodeLoadBalancerNotFoundException: 751 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 752 case elbv2.ErrCodeTargetGroupNotFoundException: 753 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 754 case elbv2.ErrCodeListenerNotFoundException: 755 fmt.Println(elbv2.ErrCodeListenerNotFoundException, aerr.Error()) 756 case elbv2.ErrCodeRuleNotFoundException: 757 fmt.Println(elbv2.ErrCodeRuleNotFoundException, aerr.Error()) 758 default: 759 fmt.Println(aerr.Error()) 760 } 761 } else { 762 // Print the error, cast err to awserr.Error to get the Code and 763 // Message from an error. 764 fmt.Println(err.Error()) 765 } 766 return 767 } 768 769 fmt.Println(result) 770} 771 772// To describe target group attributes 773// 774// This example describes the attributes of the specified target group. 775func ExampleELBV2_DescribeTargetGroupAttributes_shared00() { 776 svc := elbv2.New(session.New()) 777 input := &elbv2.DescribeTargetGroupAttributesInput{ 778 TargetGroupArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"), 779 } 780 781 result, err := svc.DescribeTargetGroupAttributes(input) 782 if err != nil { 783 if aerr, ok := err.(awserr.Error); ok { 784 switch aerr.Code() { 785 case elbv2.ErrCodeTargetGroupNotFoundException: 786 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 787 default: 788 fmt.Println(aerr.Error()) 789 } 790 } else { 791 // Print the error, cast err to awserr.Error to get the Code and 792 // Message from an error. 793 fmt.Println(err.Error()) 794 } 795 return 796 } 797 798 fmt.Println(result) 799} 800 801// To describe a target group 802// 803// This example describes the specified target group. 804func ExampleELBV2_DescribeTargetGroups_shared00() { 805 svc := elbv2.New(session.New()) 806 input := &elbv2.DescribeTargetGroupsInput{ 807 TargetGroupArns: []*string{ 808 aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"), 809 }, 810 } 811 812 result, err := svc.DescribeTargetGroups(input) 813 if err != nil { 814 if aerr, ok := err.(awserr.Error); ok { 815 switch aerr.Code() { 816 case elbv2.ErrCodeLoadBalancerNotFoundException: 817 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 818 case elbv2.ErrCodeTargetGroupNotFoundException: 819 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 820 default: 821 fmt.Println(aerr.Error()) 822 } 823 } else { 824 // Print the error, cast err to awserr.Error to get the Code and 825 // Message from an error. 826 fmt.Println(err.Error()) 827 } 828 return 829 } 830 831 fmt.Println(result) 832} 833 834// To describe the health of the targets for a target group 835// 836// This example describes the health of the targets for the specified target group. 837// One target is healthy but the other is not specified in an action, so it can't receive 838// traffic from the load balancer. 839func ExampleELBV2_DescribeTargetHealth_shared00() { 840 svc := elbv2.New(session.New()) 841 input := &elbv2.DescribeTargetHealthInput{ 842 TargetGroupArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"), 843 } 844 845 result, err := svc.DescribeTargetHealth(input) 846 if err != nil { 847 if aerr, ok := err.(awserr.Error); ok { 848 switch aerr.Code() { 849 case elbv2.ErrCodeInvalidTargetException: 850 fmt.Println(elbv2.ErrCodeInvalidTargetException, aerr.Error()) 851 case elbv2.ErrCodeTargetGroupNotFoundException: 852 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 853 case elbv2.ErrCodeHealthUnavailableException: 854 fmt.Println(elbv2.ErrCodeHealthUnavailableException, aerr.Error()) 855 default: 856 fmt.Println(aerr.Error()) 857 } 858 } else { 859 // Print the error, cast err to awserr.Error to get the Code and 860 // Message from an error. 861 fmt.Println(err.Error()) 862 } 863 return 864 } 865 866 fmt.Println(result) 867} 868 869// To describe the health of a target 870// 871// This example describes the health of the specified target. This target is healthy. 872func ExampleELBV2_DescribeTargetHealth_shared01() { 873 svc := elbv2.New(session.New()) 874 input := &elbv2.DescribeTargetHealthInput{ 875 TargetGroupArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"), 876 Targets: []*elbv2.TargetDescription{ 877 { 878 Id: aws.String("i-0f76fade"), 879 Port: aws.Int64(80), 880 }, 881 }, 882 } 883 884 result, err := svc.DescribeTargetHealth(input) 885 if err != nil { 886 if aerr, ok := err.(awserr.Error); ok { 887 switch aerr.Code() { 888 case elbv2.ErrCodeInvalidTargetException: 889 fmt.Println(elbv2.ErrCodeInvalidTargetException, aerr.Error()) 890 case elbv2.ErrCodeTargetGroupNotFoundException: 891 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 892 case elbv2.ErrCodeHealthUnavailableException: 893 fmt.Println(elbv2.ErrCodeHealthUnavailableException, aerr.Error()) 894 default: 895 fmt.Println(aerr.Error()) 896 } 897 } else { 898 // Print the error, cast err to awserr.Error to get the Code and 899 // Message from an error. 900 fmt.Println(err.Error()) 901 } 902 return 903 } 904 905 fmt.Println(result) 906} 907 908// To change the default action for a listener 909// 910// This example changes the default action for the specified listener. 911func ExampleELBV2_ModifyListener_shared00() { 912 svc := elbv2.New(session.New()) 913 input := &elbv2.ModifyListenerInput{ 914 DefaultActions: []*elbv2.Action{ 915 { 916 TargetGroupArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-new-targets/2453ed029918f21f"), 917 Type: aws.String("forward"), 918 }, 919 }, 920 ListenerArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2"), 921 } 922 923 result, err := svc.ModifyListener(input) 924 if err != nil { 925 if aerr, ok := err.(awserr.Error); ok { 926 switch aerr.Code() { 927 case elbv2.ErrCodeDuplicateListenerException: 928 fmt.Println(elbv2.ErrCodeDuplicateListenerException, aerr.Error()) 929 case elbv2.ErrCodeTooManyListenersException: 930 fmt.Println(elbv2.ErrCodeTooManyListenersException, aerr.Error()) 931 case elbv2.ErrCodeTooManyCertificatesException: 932 fmt.Println(elbv2.ErrCodeTooManyCertificatesException, aerr.Error()) 933 case elbv2.ErrCodeListenerNotFoundException: 934 fmt.Println(elbv2.ErrCodeListenerNotFoundException, aerr.Error()) 935 case elbv2.ErrCodeTargetGroupNotFoundException: 936 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 937 case elbv2.ErrCodeTargetGroupAssociationLimitException: 938 fmt.Println(elbv2.ErrCodeTargetGroupAssociationLimitException, aerr.Error()) 939 case elbv2.ErrCodeIncompatibleProtocolsException: 940 fmt.Println(elbv2.ErrCodeIncompatibleProtocolsException, aerr.Error()) 941 case elbv2.ErrCodeSSLPolicyNotFoundException: 942 fmt.Println(elbv2.ErrCodeSSLPolicyNotFoundException, aerr.Error()) 943 case elbv2.ErrCodeCertificateNotFoundException: 944 fmt.Println(elbv2.ErrCodeCertificateNotFoundException, aerr.Error()) 945 case elbv2.ErrCodeInvalidConfigurationRequestException: 946 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 947 case elbv2.ErrCodeUnsupportedProtocolException: 948 fmt.Println(elbv2.ErrCodeUnsupportedProtocolException, aerr.Error()) 949 case elbv2.ErrCodeTooManyRegistrationsForTargetIdException: 950 fmt.Println(elbv2.ErrCodeTooManyRegistrationsForTargetIdException, aerr.Error()) 951 case elbv2.ErrCodeTooManyTargetsException: 952 fmt.Println(elbv2.ErrCodeTooManyTargetsException, aerr.Error()) 953 default: 954 fmt.Println(aerr.Error()) 955 } 956 } else { 957 // Print the error, cast err to awserr.Error to get the Code and 958 // Message from an error. 959 fmt.Println(err.Error()) 960 } 961 return 962 } 963 964 fmt.Println(result) 965} 966 967// To change the server certificate 968// 969// This example changes the server certificate for the specified HTTPS listener. 970func ExampleELBV2_ModifyListener_shared01() { 971 svc := elbv2.New(session.New()) 972 input := &elbv2.ModifyListenerInput{ 973 Certificates: []*elbv2.Certificate{ 974 { 975 CertificateArn: aws.String("arn:aws:iam::123456789012:server-certificate/my-new-server-cert"), 976 }, 977 }, 978 ListenerArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/0467ef3c8400ae65"), 979 } 980 981 result, err := svc.ModifyListener(input) 982 if err != nil { 983 if aerr, ok := err.(awserr.Error); ok { 984 switch aerr.Code() { 985 case elbv2.ErrCodeDuplicateListenerException: 986 fmt.Println(elbv2.ErrCodeDuplicateListenerException, aerr.Error()) 987 case elbv2.ErrCodeTooManyListenersException: 988 fmt.Println(elbv2.ErrCodeTooManyListenersException, aerr.Error()) 989 case elbv2.ErrCodeTooManyCertificatesException: 990 fmt.Println(elbv2.ErrCodeTooManyCertificatesException, aerr.Error()) 991 case elbv2.ErrCodeListenerNotFoundException: 992 fmt.Println(elbv2.ErrCodeListenerNotFoundException, aerr.Error()) 993 case elbv2.ErrCodeTargetGroupNotFoundException: 994 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 995 case elbv2.ErrCodeTargetGroupAssociationLimitException: 996 fmt.Println(elbv2.ErrCodeTargetGroupAssociationLimitException, aerr.Error()) 997 case elbv2.ErrCodeIncompatibleProtocolsException: 998 fmt.Println(elbv2.ErrCodeIncompatibleProtocolsException, aerr.Error()) 999 case elbv2.ErrCodeSSLPolicyNotFoundException: 1000 fmt.Println(elbv2.ErrCodeSSLPolicyNotFoundException, aerr.Error()) 1001 case elbv2.ErrCodeCertificateNotFoundException: 1002 fmt.Println(elbv2.ErrCodeCertificateNotFoundException, aerr.Error()) 1003 case elbv2.ErrCodeInvalidConfigurationRequestException: 1004 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1005 case elbv2.ErrCodeUnsupportedProtocolException: 1006 fmt.Println(elbv2.ErrCodeUnsupportedProtocolException, aerr.Error()) 1007 case elbv2.ErrCodeTooManyRegistrationsForTargetIdException: 1008 fmt.Println(elbv2.ErrCodeTooManyRegistrationsForTargetIdException, aerr.Error()) 1009 case elbv2.ErrCodeTooManyTargetsException: 1010 fmt.Println(elbv2.ErrCodeTooManyTargetsException, aerr.Error()) 1011 default: 1012 fmt.Println(aerr.Error()) 1013 } 1014 } else { 1015 // Print the error, cast err to awserr.Error to get the Code and 1016 // Message from an error. 1017 fmt.Println(err.Error()) 1018 } 1019 return 1020 } 1021 1022 fmt.Println(result) 1023} 1024 1025// To enable deletion protection 1026// 1027// This example enables deletion protection for the specified load balancer. 1028func ExampleELBV2_ModifyLoadBalancerAttributes_shared00() { 1029 svc := elbv2.New(session.New()) 1030 input := &elbv2.ModifyLoadBalancerAttributesInput{ 1031 Attributes: []*elbv2.LoadBalancerAttribute{ 1032 { 1033 Key: aws.String("deletion_protection.enabled"), 1034 Value: aws.String("true"), 1035 }, 1036 }, 1037 LoadBalancerArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"), 1038 } 1039 1040 result, err := svc.ModifyLoadBalancerAttributes(input) 1041 if err != nil { 1042 if aerr, ok := err.(awserr.Error); ok { 1043 switch aerr.Code() { 1044 case elbv2.ErrCodeLoadBalancerNotFoundException: 1045 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 1046 case elbv2.ErrCodeInvalidConfigurationRequestException: 1047 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1048 default: 1049 fmt.Println(aerr.Error()) 1050 } 1051 } else { 1052 // Print the error, cast err to awserr.Error to get the Code and 1053 // Message from an error. 1054 fmt.Println(err.Error()) 1055 } 1056 return 1057 } 1058 1059 fmt.Println(result) 1060} 1061 1062// To change the idle timeout 1063// 1064// This example changes the idle timeout value for the specified load balancer. 1065func ExampleELBV2_ModifyLoadBalancerAttributes_shared01() { 1066 svc := elbv2.New(session.New()) 1067 input := &elbv2.ModifyLoadBalancerAttributesInput{ 1068 Attributes: []*elbv2.LoadBalancerAttribute{ 1069 { 1070 Key: aws.String("idle_timeout.timeout_seconds"), 1071 Value: aws.String("30"), 1072 }, 1073 }, 1074 LoadBalancerArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"), 1075 } 1076 1077 result, err := svc.ModifyLoadBalancerAttributes(input) 1078 if err != nil { 1079 if aerr, ok := err.(awserr.Error); ok { 1080 switch aerr.Code() { 1081 case elbv2.ErrCodeLoadBalancerNotFoundException: 1082 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 1083 case elbv2.ErrCodeInvalidConfigurationRequestException: 1084 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1085 default: 1086 fmt.Println(aerr.Error()) 1087 } 1088 } else { 1089 // Print the error, cast err to awserr.Error to get the Code and 1090 // Message from an error. 1091 fmt.Println(err.Error()) 1092 } 1093 return 1094 } 1095 1096 fmt.Println(result) 1097} 1098 1099// To enable access logs 1100// 1101// This example enables access logs for the specified load balancer. Note that the S3 1102// bucket must exist in the same region as the load balancer and must have a policy 1103// attached that grants access to the Elastic Load Balancing service. 1104func ExampleELBV2_ModifyLoadBalancerAttributes_shared02() { 1105 svc := elbv2.New(session.New()) 1106 input := &elbv2.ModifyLoadBalancerAttributesInput{ 1107 Attributes: []*elbv2.LoadBalancerAttribute{ 1108 { 1109 Key: aws.String("access_logs.s3.enabled"), 1110 Value: aws.String("true"), 1111 }, 1112 { 1113 Key: aws.String("access_logs.s3.bucket"), 1114 Value: aws.String("my-loadbalancer-logs"), 1115 }, 1116 { 1117 Key: aws.String("access_logs.s3.prefix"), 1118 Value: aws.String("myapp"), 1119 }, 1120 }, 1121 LoadBalancerArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"), 1122 } 1123 1124 result, err := svc.ModifyLoadBalancerAttributes(input) 1125 if err != nil { 1126 if aerr, ok := err.(awserr.Error); ok { 1127 switch aerr.Code() { 1128 case elbv2.ErrCodeLoadBalancerNotFoundException: 1129 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 1130 case elbv2.ErrCodeInvalidConfigurationRequestException: 1131 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1132 default: 1133 fmt.Println(aerr.Error()) 1134 } 1135 } else { 1136 // Print the error, cast err to awserr.Error to get the Code and 1137 // Message from an error. 1138 fmt.Println(err.Error()) 1139 } 1140 return 1141 } 1142 1143 fmt.Println(result) 1144} 1145 1146// To modify a rule 1147// 1148// This example modifies the condition for the specified rule. 1149func ExampleELBV2_ModifyRule_shared00() { 1150 svc := elbv2.New(session.New()) 1151 input := &elbv2.ModifyRuleInput{ 1152 Conditions: []*elbv2.RuleCondition{ 1153 { 1154 Field: aws.String("path-pattern"), 1155 Values: []*string{ 1156 aws.String("/images/*"), 1157 }, 1158 }, 1159 }, 1160 RuleArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:listener-rule/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2/9683b2d02a6cabee"), 1161 } 1162 1163 result, err := svc.ModifyRule(input) 1164 if err != nil { 1165 if aerr, ok := err.(awserr.Error); ok { 1166 switch aerr.Code() { 1167 case elbv2.ErrCodeTargetGroupAssociationLimitException: 1168 fmt.Println(elbv2.ErrCodeTargetGroupAssociationLimitException, aerr.Error()) 1169 case elbv2.ErrCodeIncompatibleProtocolsException: 1170 fmt.Println(elbv2.ErrCodeIncompatibleProtocolsException, aerr.Error()) 1171 case elbv2.ErrCodeRuleNotFoundException: 1172 fmt.Println(elbv2.ErrCodeRuleNotFoundException, aerr.Error()) 1173 case elbv2.ErrCodeOperationNotPermittedException: 1174 fmt.Println(elbv2.ErrCodeOperationNotPermittedException, aerr.Error()) 1175 case elbv2.ErrCodeTooManyRegistrationsForTargetIdException: 1176 fmt.Println(elbv2.ErrCodeTooManyRegistrationsForTargetIdException, aerr.Error()) 1177 case elbv2.ErrCodeTooManyTargetsException: 1178 fmt.Println(elbv2.ErrCodeTooManyTargetsException, aerr.Error()) 1179 case elbv2.ErrCodeTargetGroupNotFoundException: 1180 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 1181 default: 1182 fmt.Println(aerr.Error()) 1183 } 1184 } else { 1185 // Print the error, cast err to awserr.Error to get the Code and 1186 // Message from an error. 1187 fmt.Println(err.Error()) 1188 } 1189 return 1190 } 1191 1192 fmt.Println(result) 1193} 1194 1195// To modify the health check configuration for a target group 1196// 1197// This example changes the configuration of the health checks used to evaluate the 1198// health of the targets for the specified target group. 1199func ExampleELBV2_ModifyTargetGroup_shared00() { 1200 svc := elbv2.New(session.New()) 1201 input := &elbv2.ModifyTargetGroupInput{ 1202 HealthCheckPort: aws.String("443"), 1203 HealthCheckProtocol: aws.String("HTTPS"), 1204 TargetGroupArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-https-targets/2453ed029918f21f"), 1205 } 1206 1207 result, err := svc.ModifyTargetGroup(input) 1208 if err != nil { 1209 if aerr, ok := err.(awserr.Error); ok { 1210 switch aerr.Code() { 1211 case elbv2.ErrCodeTargetGroupNotFoundException: 1212 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 1213 case elbv2.ErrCodeInvalidConfigurationRequestException: 1214 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1215 default: 1216 fmt.Println(aerr.Error()) 1217 } 1218 } else { 1219 // Print the error, cast err to awserr.Error to get the Code and 1220 // Message from an error. 1221 fmt.Println(err.Error()) 1222 } 1223 return 1224 } 1225 1226 fmt.Println(result) 1227} 1228 1229// To modify the deregistration delay timeout 1230// 1231// This example sets the deregistration delay timeout to the specified value for the 1232// specified target group. 1233func ExampleELBV2_ModifyTargetGroupAttributes_shared00() { 1234 svc := elbv2.New(session.New()) 1235 input := &elbv2.ModifyTargetGroupAttributesInput{ 1236 Attributes: []*elbv2.TargetGroupAttribute{ 1237 { 1238 Key: aws.String("deregistration_delay.timeout_seconds"), 1239 Value: aws.String("600"), 1240 }, 1241 }, 1242 TargetGroupArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"), 1243 } 1244 1245 result, err := svc.ModifyTargetGroupAttributes(input) 1246 if err != nil { 1247 if aerr, ok := err.(awserr.Error); ok { 1248 switch aerr.Code() { 1249 case elbv2.ErrCodeTargetGroupNotFoundException: 1250 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 1251 case elbv2.ErrCodeInvalidConfigurationRequestException: 1252 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1253 default: 1254 fmt.Println(aerr.Error()) 1255 } 1256 } else { 1257 // Print the error, cast err to awserr.Error to get the Code and 1258 // Message from an error. 1259 fmt.Println(err.Error()) 1260 } 1261 return 1262 } 1263 1264 fmt.Println(result) 1265} 1266 1267// To register targets with a target group 1268// 1269// This example registers the specified instances with the specified target group. 1270func ExampleELBV2_RegisterTargets_shared00() { 1271 svc := elbv2.New(session.New()) 1272 input := &elbv2.RegisterTargetsInput{ 1273 TargetGroupArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"), 1274 Targets: []*elbv2.TargetDescription{ 1275 { 1276 Id: aws.String("i-80c8dd94"), 1277 }, 1278 { 1279 Id: aws.String("i-ceddcd4d"), 1280 }, 1281 }, 1282 } 1283 1284 result, err := svc.RegisterTargets(input) 1285 if err != nil { 1286 if aerr, ok := err.(awserr.Error); ok { 1287 switch aerr.Code() { 1288 case elbv2.ErrCodeTargetGroupNotFoundException: 1289 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 1290 case elbv2.ErrCodeTooManyTargetsException: 1291 fmt.Println(elbv2.ErrCodeTooManyTargetsException, aerr.Error()) 1292 case elbv2.ErrCodeInvalidTargetException: 1293 fmt.Println(elbv2.ErrCodeInvalidTargetException, aerr.Error()) 1294 case elbv2.ErrCodeTooManyRegistrationsForTargetIdException: 1295 fmt.Println(elbv2.ErrCodeTooManyRegistrationsForTargetIdException, aerr.Error()) 1296 default: 1297 fmt.Println(aerr.Error()) 1298 } 1299 } else { 1300 // Print the error, cast err to awserr.Error to get the Code and 1301 // Message from an error. 1302 fmt.Println(err.Error()) 1303 } 1304 return 1305 } 1306 1307 fmt.Println(result) 1308} 1309 1310// To register targets with a target group using port overrides 1311// 1312// This example registers the specified instance with the specified target group using 1313// multiple ports. This enables you to register ECS containers on the same instance 1314// as targets in the target group. 1315func ExampleELBV2_RegisterTargets_shared01() { 1316 svc := elbv2.New(session.New()) 1317 input := &elbv2.RegisterTargetsInput{ 1318 TargetGroupArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-new-targets/3bb63f11dfb0faf9"), 1319 Targets: []*elbv2.TargetDescription{ 1320 { 1321 Id: aws.String("i-80c8dd94"), 1322 Port: aws.Int64(80), 1323 }, 1324 { 1325 Id: aws.String("i-80c8dd94"), 1326 Port: aws.Int64(766), 1327 }, 1328 }, 1329 } 1330 1331 result, err := svc.RegisterTargets(input) 1332 if err != nil { 1333 if aerr, ok := err.(awserr.Error); ok { 1334 switch aerr.Code() { 1335 case elbv2.ErrCodeTargetGroupNotFoundException: 1336 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 1337 case elbv2.ErrCodeTooManyTargetsException: 1338 fmt.Println(elbv2.ErrCodeTooManyTargetsException, aerr.Error()) 1339 case elbv2.ErrCodeInvalidTargetException: 1340 fmt.Println(elbv2.ErrCodeInvalidTargetException, aerr.Error()) 1341 case elbv2.ErrCodeTooManyRegistrationsForTargetIdException: 1342 fmt.Println(elbv2.ErrCodeTooManyRegistrationsForTargetIdException, aerr.Error()) 1343 default: 1344 fmt.Println(aerr.Error()) 1345 } 1346 } else { 1347 // Print the error, cast err to awserr.Error to get the Code and 1348 // Message from an error. 1349 fmt.Println(err.Error()) 1350 } 1351 return 1352 } 1353 1354 fmt.Println(result) 1355} 1356 1357// To remove tags from a load balancer 1358// 1359// This example removes the specified tags from the specified load balancer. 1360func ExampleELBV2_RemoveTags_shared00() { 1361 svc := elbv2.New(session.New()) 1362 input := &elbv2.RemoveTagsInput{ 1363 ResourceArns: []*string{ 1364 aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"), 1365 }, 1366 TagKeys: []*string{ 1367 aws.String("project"), 1368 aws.String("department"), 1369 }, 1370 } 1371 1372 result, err := svc.RemoveTags(input) 1373 if err != nil { 1374 if aerr, ok := err.(awserr.Error); ok { 1375 switch aerr.Code() { 1376 case elbv2.ErrCodeLoadBalancerNotFoundException: 1377 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 1378 case elbv2.ErrCodeTargetGroupNotFoundException: 1379 fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error()) 1380 case elbv2.ErrCodeListenerNotFoundException: 1381 fmt.Println(elbv2.ErrCodeListenerNotFoundException, aerr.Error()) 1382 case elbv2.ErrCodeRuleNotFoundException: 1383 fmt.Println(elbv2.ErrCodeRuleNotFoundException, aerr.Error()) 1384 case elbv2.ErrCodeTooManyTagsException: 1385 fmt.Println(elbv2.ErrCodeTooManyTagsException, aerr.Error()) 1386 default: 1387 fmt.Println(aerr.Error()) 1388 } 1389 } else { 1390 // Print the error, cast err to awserr.Error to get the Code and 1391 // Message from an error. 1392 fmt.Println(err.Error()) 1393 } 1394 return 1395 } 1396 1397 fmt.Println(result) 1398} 1399 1400// To set the rule priority 1401// 1402// This example sets the priority of the specified rule. 1403func ExampleELBV2_SetRulePriorities_shared00() { 1404 svc := elbv2.New(session.New()) 1405 input := &elbv2.SetRulePrioritiesInput{ 1406 RulePriorities: []*elbv2.RulePriorityPair{ 1407 { 1408 Priority: aws.Int64(5), 1409 RuleArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:listener-rule/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2/1291d13826f405c3"), 1410 }, 1411 }, 1412 } 1413 1414 result, err := svc.SetRulePriorities(input) 1415 if err != nil { 1416 if aerr, ok := err.(awserr.Error); ok { 1417 switch aerr.Code() { 1418 case elbv2.ErrCodeRuleNotFoundException: 1419 fmt.Println(elbv2.ErrCodeRuleNotFoundException, aerr.Error()) 1420 case elbv2.ErrCodePriorityInUseException: 1421 fmt.Println(elbv2.ErrCodePriorityInUseException, aerr.Error()) 1422 case elbv2.ErrCodeOperationNotPermittedException: 1423 fmt.Println(elbv2.ErrCodeOperationNotPermittedException, aerr.Error()) 1424 default: 1425 fmt.Println(aerr.Error()) 1426 } 1427 } else { 1428 // Print the error, cast err to awserr.Error to get the Code and 1429 // Message from an error. 1430 fmt.Println(err.Error()) 1431 } 1432 return 1433 } 1434 1435 fmt.Println(result) 1436} 1437 1438// To associate a security group with a load balancer 1439// 1440// This example associates the specified security group with the specified load balancer. 1441func ExampleELBV2_SetSecurityGroups_shared00() { 1442 svc := elbv2.New(session.New()) 1443 input := &elbv2.SetSecurityGroupsInput{ 1444 LoadBalancerArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"), 1445 SecurityGroups: []*string{ 1446 aws.String("sg-5943793c"), 1447 }, 1448 } 1449 1450 result, err := svc.SetSecurityGroups(input) 1451 if err != nil { 1452 if aerr, ok := err.(awserr.Error); ok { 1453 switch aerr.Code() { 1454 case elbv2.ErrCodeLoadBalancerNotFoundException: 1455 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 1456 case elbv2.ErrCodeInvalidConfigurationRequestException: 1457 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1458 case elbv2.ErrCodeInvalidSecurityGroupException: 1459 fmt.Println(elbv2.ErrCodeInvalidSecurityGroupException, aerr.Error()) 1460 default: 1461 fmt.Println(aerr.Error()) 1462 } 1463 } else { 1464 // Print the error, cast err to awserr.Error to get the Code and 1465 // Message from an error. 1466 fmt.Println(err.Error()) 1467 } 1468 return 1469 } 1470 1471 fmt.Println(result) 1472} 1473 1474// To enable Availability Zones for a load balancer 1475// 1476// This example enables the Availability Zones for the specified subnets for the specified 1477// load balancer. 1478func ExampleELBV2_SetSubnets_shared00() { 1479 svc := elbv2.New(session.New()) 1480 input := &elbv2.SetSubnetsInput{ 1481 LoadBalancerArn: aws.String("arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"), 1482 Subnets: []*string{ 1483 aws.String("subnet-8360a9e7"), 1484 aws.String("subnet-b7d581c0"), 1485 }, 1486 } 1487 1488 result, err := svc.SetSubnets(input) 1489 if err != nil { 1490 if aerr, ok := err.(awserr.Error); ok { 1491 switch aerr.Code() { 1492 case elbv2.ErrCodeLoadBalancerNotFoundException: 1493 fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error()) 1494 case elbv2.ErrCodeInvalidConfigurationRequestException: 1495 fmt.Println(elbv2.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1496 case elbv2.ErrCodeSubnetNotFoundException: 1497 fmt.Println(elbv2.ErrCodeSubnetNotFoundException, aerr.Error()) 1498 case elbv2.ErrCodeInvalidSubnetException: 1499 fmt.Println(elbv2.ErrCodeInvalidSubnetException, aerr.Error()) 1500 case elbv2.ErrCodeAllocationIdNotFoundException: 1501 fmt.Println(elbv2.ErrCodeAllocationIdNotFoundException, aerr.Error()) 1502 case elbv2.ErrCodeAvailabilityZoneNotSupportedException: 1503 fmt.Println(elbv2.ErrCodeAvailabilityZoneNotSupportedException, aerr.Error()) 1504 default: 1505 fmt.Println(aerr.Error()) 1506 } 1507 } else { 1508 // Print the error, cast err to awserr.Error to get the Code and 1509 // Message from an error. 1510 fmt.Println(err.Error()) 1511 } 1512 return 1513 } 1514 1515 fmt.Println(result) 1516} 1517