github.com/aavshr/aws-sdk-go@v1.41.3/service/elb/examples_test.go (about) 1 // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 3 package elb_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/elb" 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 add tags to a load balancer 29 // 30 // This example adds two tags to the specified load balancer. 31 func ExampleELB_AddTags_shared00() { 32 svc := elb.New(session.New()) 33 input := &elb.AddTagsInput{ 34 LoadBalancerNames: []*string{ 35 aws.String("my-load-balancer"), 36 }, 37 Tags: []*elb.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 elb.ErrCodeAccessPointNotFoundException: 54 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 55 case elb.ErrCodeTooManyTagsException: 56 fmt.Println(elb.ErrCodeTooManyTagsException, aerr.Error()) 57 case elb.ErrCodeDuplicateTagKeysException: 58 fmt.Println(elb.ErrCodeDuplicateTagKeysException, aerr.Error()) 59 default: 60 fmt.Println(aerr.Error()) 61 } 62 } else { 63 // Print the error, cast err to awserr.Error to get the Code and 64 // Message from an error. 65 fmt.Println(err.Error()) 66 } 67 return 68 } 69 70 fmt.Println(result) 71 } 72 73 // To associate a security group with a load balancer in a VPC 74 // 75 // This example associates a security group with the specified load balancer in a VPC. 76 func ExampleELB_ApplySecurityGroupsToLoadBalancer_shared00() { 77 svc := elb.New(session.New()) 78 input := &elb.ApplySecurityGroupsToLoadBalancerInput{ 79 LoadBalancerName: aws.String("my-load-balancer"), 80 SecurityGroups: []*string{ 81 aws.String("sg-fc448899"), 82 }, 83 } 84 85 result, err := svc.ApplySecurityGroupsToLoadBalancer(input) 86 if err != nil { 87 if aerr, ok := err.(awserr.Error); ok { 88 switch aerr.Code() { 89 case elb.ErrCodeAccessPointNotFoundException: 90 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 91 case elb.ErrCodeInvalidConfigurationRequestException: 92 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 93 case elb.ErrCodeInvalidSecurityGroupException: 94 fmt.Println(elb.ErrCodeInvalidSecurityGroupException, aerr.Error()) 95 default: 96 fmt.Println(aerr.Error()) 97 } 98 } else { 99 // Print the error, cast err to awserr.Error to get the Code and 100 // Message from an error. 101 fmt.Println(err.Error()) 102 } 103 return 104 } 105 106 fmt.Println(result) 107 } 108 109 // To attach subnets to a load balancer 110 // 111 // This example adds the specified subnet to the set of configured subnets for the specified 112 // load balancer. 113 func ExampleELB_AttachLoadBalancerToSubnets_shared00() { 114 svc := elb.New(session.New()) 115 input := &elb.AttachLoadBalancerToSubnetsInput{ 116 LoadBalancerName: aws.String("my-load-balancer"), 117 Subnets: []*string{ 118 aws.String("subnet-0ecac448"), 119 }, 120 } 121 122 result, err := svc.AttachLoadBalancerToSubnets(input) 123 if err != nil { 124 if aerr, ok := err.(awserr.Error); ok { 125 switch aerr.Code() { 126 case elb.ErrCodeAccessPointNotFoundException: 127 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 128 case elb.ErrCodeInvalidConfigurationRequestException: 129 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 130 case elb.ErrCodeSubnetNotFoundException: 131 fmt.Println(elb.ErrCodeSubnetNotFoundException, aerr.Error()) 132 case elb.ErrCodeInvalidSubnetException: 133 fmt.Println(elb.ErrCodeInvalidSubnetException, aerr.Error()) 134 default: 135 fmt.Println(aerr.Error()) 136 } 137 } else { 138 // Print the error, cast err to awserr.Error to get the Code and 139 // Message from an error. 140 fmt.Println(err.Error()) 141 } 142 return 143 } 144 145 fmt.Println(result) 146 } 147 148 // To specify the health check settings for your backend EC2 instances 149 // 150 // This example specifies the health check settings used to evaluate the health of your 151 // backend EC2 instances. 152 func ExampleELB_ConfigureHealthCheck_shared00() { 153 svc := elb.New(session.New()) 154 input := &elb.ConfigureHealthCheckInput{ 155 HealthCheck: &elb.HealthCheck{ 156 HealthyThreshold: aws.Int64(2), 157 Interval: aws.Int64(30), 158 Target: aws.String("HTTP:80/png"), 159 Timeout: aws.Int64(3), 160 UnhealthyThreshold: aws.Int64(2), 161 }, 162 LoadBalancerName: aws.String("my-load-balancer"), 163 } 164 165 result, err := svc.ConfigureHealthCheck(input) 166 if err != nil { 167 if aerr, ok := err.(awserr.Error); ok { 168 switch aerr.Code() { 169 case elb.ErrCodeAccessPointNotFoundException: 170 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 171 default: 172 fmt.Println(aerr.Error()) 173 } 174 } else { 175 // Print the error, cast err to awserr.Error to get the Code and 176 // Message from an error. 177 fmt.Println(err.Error()) 178 } 179 return 180 } 181 182 fmt.Println(result) 183 } 184 185 // To generate a stickiness policy for your load balancer 186 // 187 // This example generates a stickiness policy that follows the sticky session lifetimes 188 // of the application-generated cookie. 189 func ExampleELB_CreateAppCookieStickinessPolicy_shared00() { 190 svc := elb.New(session.New()) 191 input := &elb.CreateAppCookieStickinessPolicyInput{ 192 CookieName: aws.String("my-app-cookie"), 193 LoadBalancerName: aws.String("my-load-balancer"), 194 PolicyName: aws.String("my-app-cookie-policy"), 195 } 196 197 result, err := svc.CreateAppCookieStickinessPolicy(input) 198 if err != nil { 199 if aerr, ok := err.(awserr.Error); ok { 200 switch aerr.Code() { 201 case elb.ErrCodeAccessPointNotFoundException: 202 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 203 case elb.ErrCodeDuplicatePolicyNameException: 204 fmt.Println(elb.ErrCodeDuplicatePolicyNameException, aerr.Error()) 205 case elb.ErrCodeTooManyPoliciesException: 206 fmt.Println(elb.ErrCodeTooManyPoliciesException, aerr.Error()) 207 case elb.ErrCodeInvalidConfigurationRequestException: 208 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 209 default: 210 fmt.Println(aerr.Error()) 211 } 212 } else { 213 // Print the error, cast err to awserr.Error to get the Code and 214 // Message from an error. 215 fmt.Println(err.Error()) 216 } 217 return 218 } 219 220 fmt.Println(result) 221 } 222 223 // To generate a duration-based stickiness policy for your load balancer 224 // 225 // This example generates a stickiness policy with sticky session lifetimes controlled 226 // by the specified expiration period. 227 func ExampleELB_CreateLBCookieStickinessPolicy_shared00() { 228 svc := elb.New(session.New()) 229 input := &elb.CreateLBCookieStickinessPolicyInput{ 230 CookieExpirationPeriod: aws.Int64(60), 231 LoadBalancerName: aws.String("my-load-balancer"), 232 PolicyName: aws.String("my-duration-cookie-policy"), 233 } 234 235 result, err := svc.CreateLBCookieStickinessPolicy(input) 236 if err != nil { 237 if aerr, ok := err.(awserr.Error); ok { 238 switch aerr.Code() { 239 case elb.ErrCodeAccessPointNotFoundException: 240 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 241 case elb.ErrCodeDuplicatePolicyNameException: 242 fmt.Println(elb.ErrCodeDuplicatePolicyNameException, aerr.Error()) 243 case elb.ErrCodeTooManyPoliciesException: 244 fmt.Println(elb.ErrCodeTooManyPoliciesException, aerr.Error()) 245 case elb.ErrCodeInvalidConfigurationRequestException: 246 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 247 default: 248 fmt.Println(aerr.Error()) 249 } 250 } else { 251 // Print the error, cast err to awserr.Error to get the Code and 252 // Message from an error. 253 fmt.Println(err.Error()) 254 } 255 return 256 } 257 258 fmt.Println(result) 259 } 260 261 // To create an HTTP load balancer in a VPC 262 // 263 // This example creates a load balancer with an HTTP listener in a VPC. 264 func ExampleELB_CreateLoadBalancer_shared00() { 265 svc := elb.New(session.New()) 266 input := &elb.CreateLoadBalancerInput{ 267 Listeners: []*elb.Listener{ 268 { 269 InstancePort: aws.Int64(80), 270 InstanceProtocol: aws.String("HTTP"), 271 LoadBalancerPort: aws.Int64(80), 272 Protocol: aws.String("HTTP"), 273 }, 274 }, 275 LoadBalancerName: aws.String("my-load-balancer"), 276 SecurityGroups: []*string{ 277 aws.String("sg-a61988c3"), 278 }, 279 Subnets: []*string{ 280 aws.String("subnet-15aaab61"), 281 }, 282 } 283 284 result, err := svc.CreateLoadBalancer(input) 285 if err != nil { 286 if aerr, ok := err.(awserr.Error); ok { 287 switch aerr.Code() { 288 case elb.ErrCodeDuplicateAccessPointNameException: 289 fmt.Println(elb.ErrCodeDuplicateAccessPointNameException, aerr.Error()) 290 case elb.ErrCodeTooManyAccessPointsException: 291 fmt.Println(elb.ErrCodeTooManyAccessPointsException, aerr.Error()) 292 case elb.ErrCodeCertificateNotFoundException: 293 fmt.Println(elb.ErrCodeCertificateNotFoundException, aerr.Error()) 294 case elb.ErrCodeInvalidConfigurationRequestException: 295 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 296 case elb.ErrCodeSubnetNotFoundException: 297 fmt.Println(elb.ErrCodeSubnetNotFoundException, aerr.Error()) 298 case elb.ErrCodeInvalidSubnetException: 299 fmt.Println(elb.ErrCodeInvalidSubnetException, aerr.Error()) 300 case elb.ErrCodeInvalidSecurityGroupException: 301 fmt.Println(elb.ErrCodeInvalidSecurityGroupException, aerr.Error()) 302 case elb.ErrCodeInvalidSchemeException: 303 fmt.Println(elb.ErrCodeInvalidSchemeException, aerr.Error()) 304 case elb.ErrCodeTooManyTagsException: 305 fmt.Println(elb.ErrCodeTooManyTagsException, aerr.Error()) 306 case elb.ErrCodeDuplicateTagKeysException: 307 fmt.Println(elb.ErrCodeDuplicateTagKeysException, aerr.Error()) 308 case elb.ErrCodeUnsupportedProtocolException: 309 fmt.Println(elb.ErrCodeUnsupportedProtocolException, aerr.Error()) 310 case elb.ErrCodeOperationNotPermittedException: 311 fmt.Println(elb.ErrCodeOperationNotPermittedException, aerr.Error()) 312 default: 313 fmt.Println(aerr.Error()) 314 } 315 } else { 316 // Print the error, cast err to awserr.Error to get the Code and 317 // Message from an error. 318 fmt.Println(err.Error()) 319 } 320 return 321 } 322 323 fmt.Println(result) 324 } 325 326 // To create an HTTP load balancer in EC2-Classic 327 // 328 // This example creates a load balancer with an HTTP listener in EC2-Classic. 329 func ExampleELB_CreateLoadBalancer_shared01() { 330 svc := elb.New(session.New()) 331 input := &elb.CreateLoadBalancerInput{ 332 AvailabilityZones: []*string{ 333 aws.String("us-west-2a"), 334 }, 335 Listeners: []*elb.Listener{ 336 { 337 InstancePort: aws.Int64(80), 338 InstanceProtocol: aws.String("HTTP"), 339 LoadBalancerPort: aws.Int64(80), 340 Protocol: aws.String("HTTP"), 341 }, 342 }, 343 LoadBalancerName: aws.String("my-load-balancer"), 344 } 345 346 result, err := svc.CreateLoadBalancer(input) 347 if err != nil { 348 if aerr, ok := err.(awserr.Error); ok { 349 switch aerr.Code() { 350 case elb.ErrCodeDuplicateAccessPointNameException: 351 fmt.Println(elb.ErrCodeDuplicateAccessPointNameException, aerr.Error()) 352 case elb.ErrCodeTooManyAccessPointsException: 353 fmt.Println(elb.ErrCodeTooManyAccessPointsException, aerr.Error()) 354 case elb.ErrCodeCertificateNotFoundException: 355 fmt.Println(elb.ErrCodeCertificateNotFoundException, aerr.Error()) 356 case elb.ErrCodeInvalidConfigurationRequestException: 357 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 358 case elb.ErrCodeSubnetNotFoundException: 359 fmt.Println(elb.ErrCodeSubnetNotFoundException, aerr.Error()) 360 case elb.ErrCodeInvalidSubnetException: 361 fmt.Println(elb.ErrCodeInvalidSubnetException, aerr.Error()) 362 case elb.ErrCodeInvalidSecurityGroupException: 363 fmt.Println(elb.ErrCodeInvalidSecurityGroupException, aerr.Error()) 364 case elb.ErrCodeInvalidSchemeException: 365 fmt.Println(elb.ErrCodeInvalidSchemeException, aerr.Error()) 366 case elb.ErrCodeTooManyTagsException: 367 fmt.Println(elb.ErrCodeTooManyTagsException, aerr.Error()) 368 case elb.ErrCodeDuplicateTagKeysException: 369 fmt.Println(elb.ErrCodeDuplicateTagKeysException, aerr.Error()) 370 case elb.ErrCodeUnsupportedProtocolException: 371 fmt.Println(elb.ErrCodeUnsupportedProtocolException, aerr.Error()) 372 case elb.ErrCodeOperationNotPermittedException: 373 fmt.Println(elb.ErrCodeOperationNotPermittedException, aerr.Error()) 374 default: 375 fmt.Println(aerr.Error()) 376 } 377 } else { 378 // Print the error, cast err to awserr.Error to get the Code and 379 // Message from an error. 380 fmt.Println(err.Error()) 381 } 382 return 383 } 384 385 fmt.Println(result) 386 } 387 388 // To create an HTTPS load balancer in a VPC 389 // 390 // This example creates a load balancer with an HTTPS listener in a VPC. 391 func ExampleELB_CreateLoadBalancer_shared02() { 392 svc := elb.New(session.New()) 393 input := &elb.CreateLoadBalancerInput{ 394 Listeners: []*elb.Listener{ 395 { 396 InstancePort: aws.Int64(80), 397 InstanceProtocol: aws.String("HTTP"), 398 LoadBalancerPort: aws.Int64(80), 399 Protocol: aws.String("HTTP"), 400 }, 401 { 402 InstancePort: aws.Int64(80), 403 InstanceProtocol: aws.String("HTTP"), 404 LoadBalancerPort: aws.Int64(443), 405 Protocol: aws.String("HTTPS"), 406 SSLCertificateId: aws.String("arn:aws:iam::123456789012:server-certificate/my-server-cert"), 407 }, 408 }, 409 LoadBalancerName: aws.String("my-load-balancer"), 410 SecurityGroups: []*string{ 411 aws.String("sg-a61988c3"), 412 }, 413 Subnets: []*string{ 414 aws.String("subnet-15aaab61"), 415 }, 416 } 417 418 result, err := svc.CreateLoadBalancer(input) 419 if err != nil { 420 if aerr, ok := err.(awserr.Error); ok { 421 switch aerr.Code() { 422 case elb.ErrCodeDuplicateAccessPointNameException: 423 fmt.Println(elb.ErrCodeDuplicateAccessPointNameException, aerr.Error()) 424 case elb.ErrCodeTooManyAccessPointsException: 425 fmt.Println(elb.ErrCodeTooManyAccessPointsException, aerr.Error()) 426 case elb.ErrCodeCertificateNotFoundException: 427 fmt.Println(elb.ErrCodeCertificateNotFoundException, aerr.Error()) 428 case elb.ErrCodeInvalidConfigurationRequestException: 429 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 430 case elb.ErrCodeSubnetNotFoundException: 431 fmt.Println(elb.ErrCodeSubnetNotFoundException, aerr.Error()) 432 case elb.ErrCodeInvalidSubnetException: 433 fmt.Println(elb.ErrCodeInvalidSubnetException, aerr.Error()) 434 case elb.ErrCodeInvalidSecurityGroupException: 435 fmt.Println(elb.ErrCodeInvalidSecurityGroupException, aerr.Error()) 436 case elb.ErrCodeInvalidSchemeException: 437 fmt.Println(elb.ErrCodeInvalidSchemeException, aerr.Error()) 438 case elb.ErrCodeTooManyTagsException: 439 fmt.Println(elb.ErrCodeTooManyTagsException, aerr.Error()) 440 case elb.ErrCodeDuplicateTagKeysException: 441 fmt.Println(elb.ErrCodeDuplicateTagKeysException, aerr.Error()) 442 case elb.ErrCodeUnsupportedProtocolException: 443 fmt.Println(elb.ErrCodeUnsupportedProtocolException, aerr.Error()) 444 case elb.ErrCodeOperationNotPermittedException: 445 fmt.Println(elb.ErrCodeOperationNotPermittedException, aerr.Error()) 446 default: 447 fmt.Println(aerr.Error()) 448 } 449 } else { 450 // Print the error, cast err to awserr.Error to get the Code and 451 // Message from an error. 452 fmt.Println(err.Error()) 453 } 454 return 455 } 456 457 fmt.Println(result) 458 } 459 460 // To create an HTTPS load balancer in EC2-Classic 461 // 462 // This example creates a load balancer with an HTTPS listener in EC2-Classic. 463 func ExampleELB_CreateLoadBalancer_shared03() { 464 svc := elb.New(session.New()) 465 input := &elb.CreateLoadBalancerInput{ 466 AvailabilityZones: []*string{ 467 aws.String("us-west-2a"), 468 }, 469 Listeners: []*elb.Listener{ 470 { 471 InstancePort: aws.Int64(80), 472 InstanceProtocol: aws.String("HTTP"), 473 LoadBalancerPort: aws.Int64(80), 474 Protocol: aws.String("HTTP"), 475 }, 476 { 477 InstancePort: aws.Int64(80), 478 InstanceProtocol: aws.String("HTTP"), 479 LoadBalancerPort: aws.Int64(443), 480 Protocol: aws.String("HTTPS"), 481 SSLCertificateId: aws.String("arn:aws:iam::123456789012:server-certificate/my-server-cert"), 482 }, 483 }, 484 LoadBalancerName: aws.String("my-load-balancer"), 485 } 486 487 result, err := svc.CreateLoadBalancer(input) 488 if err != nil { 489 if aerr, ok := err.(awserr.Error); ok { 490 switch aerr.Code() { 491 case elb.ErrCodeDuplicateAccessPointNameException: 492 fmt.Println(elb.ErrCodeDuplicateAccessPointNameException, aerr.Error()) 493 case elb.ErrCodeTooManyAccessPointsException: 494 fmt.Println(elb.ErrCodeTooManyAccessPointsException, aerr.Error()) 495 case elb.ErrCodeCertificateNotFoundException: 496 fmt.Println(elb.ErrCodeCertificateNotFoundException, aerr.Error()) 497 case elb.ErrCodeInvalidConfigurationRequestException: 498 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 499 case elb.ErrCodeSubnetNotFoundException: 500 fmt.Println(elb.ErrCodeSubnetNotFoundException, aerr.Error()) 501 case elb.ErrCodeInvalidSubnetException: 502 fmt.Println(elb.ErrCodeInvalidSubnetException, aerr.Error()) 503 case elb.ErrCodeInvalidSecurityGroupException: 504 fmt.Println(elb.ErrCodeInvalidSecurityGroupException, aerr.Error()) 505 case elb.ErrCodeInvalidSchemeException: 506 fmt.Println(elb.ErrCodeInvalidSchemeException, aerr.Error()) 507 case elb.ErrCodeTooManyTagsException: 508 fmt.Println(elb.ErrCodeTooManyTagsException, aerr.Error()) 509 case elb.ErrCodeDuplicateTagKeysException: 510 fmt.Println(elb.ErrCodeDuplicateTagKeysException, aerr.Error()) 511 case elb.ErrCodeUnsupportedProtocolException: 512 fmt.Println(elb.ErrCodeUnsupportedProtocolException, aerr.Error()) 513 case elb.ErrCodeOperationNotPermittedException: 514 fmt.Println(elb.ErrCodeOperationNotPermittedException, aerr.Error()) 515 default: 516 fmt.Println(aerr.Error()) 517 } 518 } else { 519 // Print the error, cast err to awserr.Error to get the Code and 520 // Message from an error. 521 fmt.Println(err.Error()) 522 } 523 return 524 } 525 526 fmt.Println(result) 527 } 528 529 // To create an internal load balancer 530 // 531 // This example creates an internal load balancer with an HTTP listener in a VPC. 532 func ExampleELB_CreateLoadBalancer_shared04() { 533 svc := elb.New(session.New()) 534 input := &elb.CreateLoadBalancerInput{ 535 Listeners: []*elb.Listener{ 536 { 537 InstancePort: aws.Int64(80), 538 InstanceProtocol: aws.String("HTTP"), 539 LoadBalancerPort: aws.Int64(80), 540 Protocol: aws.String("HTTP"), 541 }, 542 }, 543 LoadBalancerName: aws.String("my-load-balancer"), 544 Scheme: aws.String("internal"), 545 SecurityGroups: []*string{ 546 aws.String("sg-a61988c3"), 547 }, 548 Subnets: []*string{ 549 aws.String("subnet-15aaab61"), 550 }, 551 } 552 553 result, err := svc.CreateLoadBalancer(input) 554 if err != nil { 555 if aerr, ok := err.(awserr.Error); ok { 556 switch aerr.Code() { 557 case elb.ErrCodeDuplicateAccessPointNameException: 558 fmt.Println(elb.ErrCodeDuplicateAccessPointNameException, aerr.Error()) 559 case elb.ErrCodeTooManyAccessPointsException: 560 fmt.Println(elb.ErrCodeTooManyAccessPointsException, aerr.Error()) 561 case elb.ErrCodeCertificateNotFoundException: 562 fmt.Println(elb.ErrCodeCertificateNotFoundException, aerr.Error()) 563 case elb.ErrCodeInvalidConfigurationRequestException: 564 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 565 case elb.ErrCodeSubnetNotFoundException: 566 fmt.Println(elb.ErrCodeSubnetNotFoundException, aerr.Error()) 567 case elb.ErrCodeInvalidSubnetException: 568 fmt.Println(elb.ErrCodeInvalidSubnetException, aerr.Error()) 569 case elb.ErrCodeInvalidSecurityGroupException: 570 fmt.Println(elb.ErrCodeInvalidSecurityGroupException, aerr.Error()) 571 case elb.ErrCodeInvalidSchemeException: 572 fmt.Println(elb.ErrCodeInvalidSchemeException, aerr.Error()) 573 case elb.ErrCodeTooManyTagsException: 574 fmt.Println(elb.ErrCodeTooManyTagsException, aerr.Error()) 575 case elb.ErrCodeDuplicateTagKeysException: 576 fmt.Println(elb.ErrCodeDuplicateTagKeysException, aerr.Error()) 577 case elb.ErrCodeUnsupportedProtocolException: 578 fmt.Println(elb.ErrCodeUnsupportedProtocolException, aerr.Error()) 579 case elb.ErrCodeOperationNotPermittedException: 580 fmt.Println(elb.ErrCodeOperationNotPermittedException, aerr.Error()) 581 default: 582 fmt.Println(aerr.Error()) 583 } 584 } else { 585 // Print the error, cast err to awserr.Error to get the Code and 586 // Message from an error. 587 fmt.Println(err.Error()) 588 } 589 return 590 } 591 592 fmt.Println(result) 593 } 594 595 // To create an HTTP listener for a load balancer 596 // 597 // This example creates a listener for your load balancer at port 80 using the HTTP 598 // protocol. 599 func ExampleELB_CreateLoadBalancerListeners_shared00() { 600 svc := elb.New(session.New()) 601 input := &elb.CreateLoadBalancerListenersInput{ 602 Listeners: []*elb.Listener{ 603 { 604 InstancePort: aws.Int64(80), 605 InstanceProtocol: aws.String("HTTP"), 606 LoadBalancerPort: aws.Int64(80), 607 Protocol: aws.String("HTTP"), 608 }, 609 }, 610 LoadBalancerName: aws.String("my-load-balancer"), 611 } 612 613 result, err := svc.CreateLoadBalancerListeners(input) 614 if err != nil { 615 if aerr, ok := err.(awserr.Error); ok { 616 switch aerr.Code() { 617 case elb.ErrCodeAccessPointNotFoundException: 618 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 619 case elb.ErrCodeDuplicateListenerException: 620 fmt.Println(elb.ErrCodeDuplicateListenerException, aerr.Error()) 621 case elb.ErrCodeCertificateNotFoundException: 622 fmt.Println(elb.ErrCodeCertificateNotFoundException, aerr.Error()) 623 case elb.ErrCodeInvalidConfigurationRequestException: 624 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 625 case elb.ErrCodeUnsupportedProtocolException: 626 fmt.Println(elb.ErrCodeUnsupportedProtocolException, aerr.Error()) 627 default: 628 fmt.Println(aerr.Error()) 629 } 630 } else { 631 // Print the error, cast err to awserr.Error to get the Code and 632 // Message from an error. 633 fmt.Println(err.Error()) 634 } 635 return 636 } 637 638 fmt.Println(result) 639 } 640 641 // To create an HTTPS listener for a load balancer 642 // 643 // This example creates a listener for your load balancer at port 443 using the HTTPS 644 // protocol. 645 func ExampleELB_CreateLoadBalancerListeners_shared01() { 646 svc := elb.New(session.New()) 647 input := &elb.CreateLoadBalancerListenersInput{ 648 Listeners: []*elb.Listener{ 649 { 650 InstancePort: aws.Int64(80), 651 InstanceProtocol: aws.String("HTTP"), 652 LoadBalancerPort: aws.Int64(443), 653 Protocol: aws.String("HTTPS"), 654 SSLCertificateId: aws.String("arn:aws:iam::123456789012:server-certificate/my-server-cert"), 655 }, 656 }, 657 LoadBalancerName: aws.String("my-load-balancer"), 658 } 659 660 result, err := svc.CreateLoadBalancerListeners(input) 661 if err != nil { 662 if aerr, ok := err.(awserr.Error); ok { 663 switch aerr.Code() { 664 case elb.ErrCodeAccessPointNotFoundException: 665 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 666 case elb.ErrCodeDuplicateListenerException: 667 fmt.Println(elb.ErrCodeDuplicateListenerException, aerr.Error()) 668 case elb.ErrCodeCertificateNotFoundException: 669 fmt.Println(elb.ErrCodeCertificateNotFoundException, aerr.Error()) 670 case elb.ErrCodeInvalidConfigurationRequestException: 671 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 672 case elb.ErrCodeUnsupportedProtocolException: 673 fmt.Println(elb.ErrCodeUnsupportedProtocolException, aerr.Error()) 674 default: 675 fmt.Println(aerr.Error()) 676 } 677 } else { 678 // Print the error, cast err to awserr.Error to get the Code and 679 // Message from an error. 680 fmt.Println(err.Error()) 681 } 682 return 683 } 684 685 fmt.Println(result) 686 } 687 688 // To create a policy that enables Proxy Protocol on a load balancer 689 // 690 // This example creates a policy that enables Proxy Protocol on the specified load balancer. 691 func ExampleELB_CreateLoadBalancerPolicy_shared00() { 692 svc := elb.New(session.New()) 693 input := &elb.CreateLoadBalancerPolicyInput{ 694 LoadBalancerName: aws.String("my-load-balancer"), 695 PolicyAttributes: []*elb.PolicyAttribute{ 696 { 697 AttributeName: aws.String("ProxyProtocol"), 698 AttributeValue: aws.String("true"), 699 }, 700 }, 701 PolicyName: aws.String("my-ProxyProtocol-policy"), 702 PolicyTypeName: aws.String("ProxyProtocolPolicyType"), 703 } 704 705 result, err := svc.CreateLoadBalancerPolicy(input) 706 if err != nil { 707 if aerr, ok := err.(awserr.Error); ok { 708 switch aerr.Code() { 709 case elb.ErrCodeAccessPointNotFoundException: 710 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 711 case elb.ErrCodePolicyTypeNotFoundException: 712 fmt.Println(elb.ErrCodePolicyTypeNotFoundException, aerr.Error()) 713 case elb.ErrCodeDuplicatePolicyNameException: 714 fmt.Println(elb.ErrCodeDuplicatePolicyNameException, aerr.Error()) 715 case elb.ErrCodeTooManyPoliciesException: 716 fmt.Println(elb.ErrCodeTooManyPoliciesException, aerr.Error()) 717 case elb.ErrCodeInvalidConfigurationRequestException: 718 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 719 default: 720 fmt.Println(aerr.Error()) 721 } 722 } else { 723 // Print the error, cast err to awserr.Error to get the Code and 724 // Message from an error. 725 fmt.Println(err.Error()) 726 } 727 return 728 } 729 730 fmt.Println(result) 731 } 732 733 // To create a public key policy 734 // 735 // This example creates a public key policy. 736 func ExampleELB_CreateLoadBalancerPolicy_shared01() { 737 svc := elb.New(session.New()) 738 input := &elb.CreateLoadBalancerPolicyInput{ 739 LoadBalancerName: aws.String("my-load-balancer"), 740 PolicyAttributes: []*elb.PolicyAttribute{ 741 { 742 AttributeName: aws.String("PublicKey"), 743 AttributeValue: aws.String("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwAYUjnfyEyXr1pxjhFWBpMlggUcqoi3kl+dS74kj//c6x7ROtusUaeQCTgIUkayttRDWchuqo1pHC1u+n5xxXnBBe2ejbb2WRsKIQ5rXEeixsjFpFsojpSQKkzhVGI6mJVZBJDVKSHmswnwLBdofLhzvllpovBPTHe+o4haAWvDBALJU0pkSI1FecPHcs2hwxf14zHoXy1e2k36A64nXW43wtfx5qcVSIxtCEOjnYRg7RPvybaGfQ+v6Iaxb/+7J5kEvZhTFQId+bSiJImF1FSUT1W1xwzBZPUbcUkkXDj45vC2s3Z8E+Lk7a3uZhvsQHLZnrfuWjBWGWvZ/MhZYgEXAMPLE"), 744 }, 745 }, 746 PolicyName: aws.String("my-PublicKey-policy"), 747 PolicyTypeName: aws.String("PublicKeyPolicyType"), 748 } 749 750 result, err := svc.CreateLoadBalancerPolicy(input) 751 if err != nil { 752 if aerr, ok := err.(awserr.Error); ok { 753 switch aerr.Code() { 754 case elb.ErrCodeAccessPointNotFoundException: 755 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 756 case elb.ErrCodePolicyTypeNotFoundException: 757 fmt.Println(elb.ErrCodePolicyTypeNotFoundException, aerr.Error()) 758 case elb.ErrCodeDuplicatePolicyNameException: 759 fmt.Println(elb.ErrCodeDuplicatePolicyNameException, aerr.Error()) 760 case elb.ErrCodeTooManyPoliciesException: 761 fmt.Println(elb.ErrCodeTooManyPoliciesException, aerr.Error()) 762 case elb.ErrCodeInvalidConfigurationRequestException: 763 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 764 default: 765 fmt.Println(aerr.Error()) 766 } 767 } else { 768 // Print the error, cast err to awserr.Error to get the Code and 769 // Message from an error. 770 fmt.Println(err.Error()) 771 } 772 return 773 } 774 775 fmt.Println(result) 776 } 777 778 // To create a backend server authentication policy 779 // 780 // This example creates a backend server authentication policy that enables authentication 781 // on your backend instance using a public key policy. 782 func ExampleELB_CreateLoadBalancerPolicy_shared02() { 783 svc := elb.New(session.New()) 784 input := &elb.CreateLoadBalancerPolicyInput{ 785 LoadBalancerName: aws.String("my-load-balancer"), 786 PolicyAttributes: []*elb.PolicyAttribute{ 787 { 788 AttributeName: aws.String("PublicKeyPolicyName"), 789 AttributeValue: aws.String("my-PublicKey-policy"), 790 }, 791 }, 792 PolicyName: aws.String("my-authentication-policy"), 793 PolicyTypeName: aws.String("BackendServerAuthenticationPolicyType"), 794 } 795 796 result, err := svc.CreateLoadBalancerPolicy(input) 797 if err != nil { 798 if aerr, ok := err.(awserr.Error); ok { 799 switch aerr.Code() { 800 case elb.ErrCodeAccessPointNotFoundException: 801 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 802 case elb.ErrCodePolicyTypeNotFoundException: 803 fmt.Println(elb.ErrCodePolicyTypeNotFoundException, aerr.Error()) 804 case elb.ErrCodeDuplicatePolicyNameException: 805 fmt.Println(elb.ErrCodeDuplicatePolicyNameException, aerr.Error()) 806 case elb.ErrCodeTooManyPoliciesException: 807 fmt.Println(elb.ErrCodeTooManyPoliciesException, aerr.Error()) 808 case elb.ErrCodeInvalidConfigurationRequestException: 809 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 810 default: 811 fmt.Println(aerr.Error()) 812 } 813 } else { 814 // Print the error, cast err to awserr.Error to get the Code and 815 // Message from an error. 816 fmt.Println(err.Error()) 817 } 818 return 819 } 820 821 fmt.Println(result) 822 } 823 824 // To delete a load balancer 825 // 826 // This example deletes the specified load balancer. 827 func ExampleELB_DeleteLoadBalancer_shared00() { 828 svc := elb.New(session.New()) 829 input := &elb.DeleteLoadBalancerInput{ 830 LoadBalancerName: aws.String("my-load-balancer"), 831 } 832 833 result, err := svc.DeleteLoadBalancer(input) 834 if err != nil { 835 if aerr, ok := err.(awserr.Error); ok { 836 switch aerr.Code() { 837 default: 838 fmt.Println(aerr.Error()) 839 } 840 } else { 841 // Print the error, cast err to awserr.Error to get the Code and 842 // Message from an error. 843 fmt.Println(err.Error()) 844 } 845 return 846 } 847 848 fmt.Println(result) 849 } 850 851 // To delete a listener from your load balancer 852 // 853 // This example deletes the listener for the specified port from the specified load 854 // balancer. 855 func ExampleELB_DeleteLoadBalancerListeners_shared00() { 856 svc := elb.New(session.New()) 857 input := &elb.DeleteLoadBalancerListenersInput{ 858 LoadBalancerName: aws.String("my-load-balancer"), 859 LoadBalancerPorts: []*int64{ 860 aws.Int64(80), 861 }, 862 } 863 864 result, err := svc.DeleteLoadBalancerListeners(input) 865 if err != nil { 866 if aerr, ok := err.(awserr.Error); ok { 867 switch aerr.Code() { 868 case elb.ErrCodeAccessPointNotFoundException: 869 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 870 default: 871 fmt.Println(aerr.Error()) 872 } 873 } else { 874 // Print the error, cast err to awserr.Error to get the Code and 875 // Message from an error. 876 fmt.Println(err.Error()) 877 } 878 return 879 } 880 881 fmt.Println(result) 882 } 883 884 // To delete a policy from your load balancer 885 // 886 // This example deletes the specified policy from the specified load balancer. The policy 887 // must not be enabled on any listener. 888 func ExampleELB_DeleteLoadBalancerPolicy_shared00() { 889 svc := elb.New(session.New()) 890 input := &elb.DeleteLoadBalancerPolicyInput{ 891 LoadBalancerName: aws.String("my-load-balancer"), 892 PolicyName: aws.String("my-duration-cookie-policy"), 893 } 894 895 result, err := svc.DeleteLoadBalancerPolicy(input) 896 if err != nil { 897 if aerr, ok := err.(awserr.Error); ok { 898 switch aerr.Code() { 899 case elb.ErrCodeAccessPointNotFoundException: 900 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 901 case elb.ErrCodeInvalidConfigurationRequestException: 902 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 903 default: 904 fmt.Println(aerr.Error()) 905 } 906 } else { 907 // Print the error, cast err to awserr.Error to get the Code and 908 // Message from an error. 909 fmt.Println(err.Error()) 910 } 911 return 912 } 913 914 fmt.Println(result) 915 } 916 917 // To deregister instances from a load balancer 918 // 919 // This example deregisters the specified instance from the specified load balancer. 920 func ExampleELB_DeregisterInstancesFromLoadBalancer_shared00() { 921 svc := elb.New(session.New()) 922 input := &elb.DeregisterInstancesFromLoadBalancerInput{ 923 Instances: []*elb.Instance{ 924 { 925 InstanceId: aws.String("i-d6f6fae3"), 926 }, 927 }, 928 LoadBalancerName: aws.String("my-load-balancer"), 929 } 930 931 result, err := svc.DeregisterInstancesFromLoadBalancer(input) 932 if err != nil { 933 if aerr, ok := err.(awserr.Error); ok { 934 switch aerr.Code() { 935 case elb.ErrCodeAccessPointNotFoundException: 936 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 937 case elb.ErrCodeInvalidEndPointException: 938 fmt.Println(elb.ErrCodeInvalidEndPointException, aerr.Error()) 939 default: 940 fmt.Println(aerr.Error()) 941 } 942 } else { 943 // Print the error, cast err to awserr.Error to get the Code and 944 // Message from an error. 945 fmt.Println(err.Error()) 946 } 947 return 948 } 949 950 fmt.Println(result) 951 } 952 953 // To describe the health of the instances for a load balancer 954 // 955 // This example describes the health of the instances for the specified load balancer. 956 func ExampleELB_DescribeInstanceHealth_shared00() { 957 svc := elb.New(session.New()) 958 input := &elb.DescribeInstanceHealthInput{ 959 LoadBalancerName: aws.String("my-load-balancer"), 960 } 961 962 result, err := svc.DescribeInstanceHealth(input) 963 if err != nil { 964 if aerr, ok := err.(awserr.Error); ok { 965 switch aerr.Code() { 966 case elb.ErrCodeAccessPointNotFoundException: 967 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 968 case elb.ErrCodeInvalidEndPointException: 969 fmt.Println(elb.ErrCodeInvalidEndPointException, aerr.Error()) 970 default: 971 fmt.Println(aerr.Error()) 972 } 973 } else { 974 // Print the error, cast err to awserr.Error to get the Code and 975 // Message from an error. 976 fmt.Println(err.Error()) 977 } 978 return 979 } 980 981 fmt.Println(result) 982 } 983 984 // To describe the attributes of a load balancer 985 // 986 // This example describes the attributes of the specified load balancer. 987 func ExampleELB_DescribeLoadBalancerAttributes_shared00() { 988 svc := elb.New(session.New()) 989 input := &elb.DescribeLoadBalancerAttributesInput{ 990 LoadBalancerName: aws.String("my-load-balancer"), 991 } 992 993 result, err := svc.DescribeLoadBalancerAttributes(input) 994 if err != nil { 995 if aerr, ok := err.(awserr.Error); ok { 996 switch aerr.Code() { 997 case elb.ErrCodeAccessPointNotFoundException: 998 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 999 case elb.ErrCodeLoadBalancerAttributeNotFoundException: 1000 fmt.Println(elb.ErrCodeLoadBalancerAttributeNotFoundException, aerr.Error()) 1001 default: 1002 fmt.Println(aerr.Error()) 1003 } 1004 } else { 1005 // Print the error, cast err to awserr.Error to get the Code and 1006 // Message from an error. 1007 fmt.Println(err.Error()) 1008 } 1009 return 1010 } 1011 1012 fmt.Println(result) 1013 } 1014 1015 // To describe a policy associated with a load balancer 1016 // 1017 // This example describes the specified policy associated with the specified load balancer. 1018 func ExampleELB_DescribeLoadBalancerPolicies_shared00() { 1019 svc := elb.New(session.New()) 1020 input := &elb.DescribeLoadBalancerPoliciesInput{ 1021 LoadBalancerName: aws.String("my-load-balancer"), 1022 PolicyNames: []*string{ 1023 aws.String("my-authentication-policy"), 1024 }, 1025 } 1026 1027 result, err := svc.DescribeLoadBalancerPolicies(input) 1028 if err != nil { 1029 if aerr, ok := err.(awserr.Error); ok { 1030 switch aerr.Code() { 1031 case elb.ErrCodeAccessPointNotFoundException: 1032 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 1033 case elb.ErrCodePolicyNotFoundException: 1034 fmt.Println(elb.ErrCodePolicyNotFoundException, aerr.Error()) 1035 default: 1036 fmt.Println(aerr.Error()) 1037 } 1038 } else { 1039 // Print the error, cast err to awserr.Error to get the Code and 1040 // Message from an error. 1041 fmt.Println(err.Error()) 1042 } 1043 return 1044 } 1045 1046 fmt.Println(result) 1047 } 1048 1049 // To describe a load balancer policy type defined by Elastic Load Balancing 1050 // 1051 // This example describes the specified load balancer policy type. 1052 func ExampleELB_DescribeLoadBalancerPolicyTypes_shared00() { 1053 svc := elb.New(session.New()) 1054 input := &elb.DescribeLoadBalancerPolicyTypesInput{ 1055 PolicyTypeNames: []*string{ 1056 aws.String("ProxyProtocolPolicyType"), 1057 }, 1058 } 1059 1060 result, err := svc.DescribeLoadBalancerPolicyTypes(input) 1061 if err != nil { 1062 if aerr, ok := err.(awserr.Error); ok { 1063 switch aerr.Code() { 1064 case elb.ErrCodePolicyTypeNotFoundException: 1065 fmt.Println(elb.ErrCodePolicyTypeNotFoundException, aerr.Error()) 1066 default: 1067 fmt.Println(aerr.Error()) 1068 } 1069 } else { 1070 // Print the error, cast err to awserr.Error to get the Code and 1071 // Message from an error. 1072 fmt.Println(err.Error()) 1073 } 1074 return 1075 } 1076 1077 fmt.Println(result) 1078 } 1079 1080 // To describe one of your load balancers 1081 // 1082 // This example describes the specified load balancer. 1083 func ExampleELB_DescribeLoadBalancers_shared00() { 1084 svc := elb.New(session.New()) 1085 input := &elb.DescribeLoadBalancersInput{ 1086 LoadBalancerNames: []*string{ 1087 aws.String("my-load-balancer"), 1088 }, 1089 } 1090 1091 result, err := svc.DescribeLoadBalancers(input) 1092 if err != nil { 1093 if aerr, ok := err.(awserr.Error); ok { 1094 switch aerr.Code() { 1095 case elb.ErrCodeAccessPointNotFoundException: 1096 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 1097 case elb.ErrCodeDependencyThrottleException: 1098 fmt.Println(elb.ErrCodeDependencyThrottleException, aerr.Error()) 1099 default: 1100 fmt.Println(aerr.Error()) 1101 } 1102 } else { 1103 // Print the error, cast err to awserr.Error to get the Code and 1104 // Message from an error. 1105 fmt.Println(err.Error()) 1106 } 1107 return 1108 } 1109 1110 fmt.Println(result) 1111 } 1112 1113 // To describe the tags for a load balancer 1114 // 1115 // This example describes the tags for the specified load balancer. 1116 func ExampleELB_DescribeTags_shared00() { 1117 svc := elb.New(session.New()) 1118 input := &elb.DescribeTagsInput{ 1119 LoadBalancerNames: []*string{ 1120 aws.String("my-load-balancer"), 1121 }, 1122 } 1123 1124 result, err := svc.DescribeTags(input) 1125 if err != nil { 1126 if aerr, ok := err.(awserr.Error); ok { 1127 switch aerr.Code() { 1128 case elb.ErrCodeAccessPointNotFoundException: 1129 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 1130 default: 1131 fmt.Println(aerr.Error()) 1132 } 1133 } else { 1134 // Print the error, cast err to awserr.Error to get the Code and 1135 // Message from an error. 1136 fmt.Println(err.Error()) 1137 } 1138 return 1139 } 1140 1141 fmt.Println(result) 1142 } 1143 1144 // To detach a load balancer from a subnet 1145 // 1146 // This example detaches the specified load balancer from the specified subnet. 1147 func ExampleELB_DetachLoadBalancerFromSubnets_shared00() { 1148 svc := elb.New(session.New()) 1149 input := &elb.DetachLoadBalancerFromSubnetsInput{ 1150 LoadBalancerName: aws.String("my-load-balancer"), 1151 Subnets: []*string{ 1152 aws.String("subnet-0ecac448"), 1153 }, 1154 } 1155 1156 result, err := svc.DetachLoadBalancerFromSubnets(input) 1157 if err != nil { 1158 if aerr, ok := err.(awserr.Error); ok { 1159 switch aerr.Code() { 1160 case elb.ErrCodeAccessPointNotFoundException: 1161 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 1162 case elb.ErrCodeInvalidConfigurationRequestException: 1163 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1164 default: 1165 fmt.Println(aerr.Error()) 1166 } 1167 } else { 1168 // Print the error, cast err to awserr.Error to get the Code and 1169 // Message from an error. 1170 fmt.Println(err.Error()) 1171 } 1172 return 1173 } 1174 1175 fmt.Println(result) 1176 } 1177 1178 // To disable an Availability Zone for a load balancer 1179 // 1180 // This example removes the specified Availability Zone from the set of Availability 1181 // Zones for the specified load balancer. 1182 func ExampleELB_DisableAvailabilityZonesForLoadBalancer_shared00() { 1183 svc := elb.New(session.New()) 1184 input := &elb.DisableAvailabilityZonesForLoadBalancerInput{ 1185 AvailabilityZones: []*string{ 1186 aws.String("us-west-2a"), 1187 }, 1188 LoadBalancerName: aws.String("my-load-balancer"), 1189 } 1190 1191 result, err := svc.DisableAvailabilityZonesForLoadBalancer(input) 1192 if err != nil { 1193 if aerr, ok := err.(awserr.Error); ok { 1194 switch aerr.Code() { 1195 case elb.ErrCodeAccessPointNotFoundException: 1196 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 1197 case elb.ErrCodeInvalidConfigurationRequestException: 1198 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1199 default: 1200 fmt.Println(aerr.Error()) 1201 } 1202 } else { 1203 // Print the error, cast err to awserr.Error to get the Code and 1204 // Message from an error. 1205 fmt.Println(err.Error()) 1206 } 1207 return 1208 } 1209 1210 fmt.Println(result) 1211 } 1212 1213 // To enable an Availability Zone for a load balancer 1214 // 1215 // This example adds the specified Availability Zone to the specified load balancer. 1216 func ExampleELB_EnableAvailabilityZonesForLoadBalancer_shared00() { 1217 svc := elb.New(session.New()) 1218 input := &elb.EnableAvailabilityZonesForLoadBalancerInput{ 1219 AvailabilityZones: []*string{ 1220 aws.String("us-west-2b"), 1221 }, 1222 LoadBalancerName: aws.String("my-load-balancer"), 1223 } 1224 1225 result, err := svc.EnableAvailabilityZonesForLoadBalancer(input) 1226 if err != nil { 1227 if aerr, ok := err.(awserr.Error); ok { 1228 switch aerr.Code() { 1229 case elb.ErrCodeAccessPointNotFoundException: 1230 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 1231 default: 1232 fmt.Println(aerr.Error()) 1233 } 1234 } else { 1235 // Print the error, cast err to awserr.Error to get the Code and 1236 // Message from an error. 1237 fmt.Println(err.Error()) 1238 } 1239 return 1240 } 1241 1242 fmt.Println(result) 1243 } 1244 1245 // To enable cross-zone load balancing 1246 // 1247 // This example enables cross-zone load balancing for the specified load balancer. 1248 func ExampleELB_ModifyLoadBalancerAttributes_shared00() { 1249 svc := elb.New(session.New()) 1250 input := &elb.ModifyLoadBalancerAttributesInput{ 1251 LoadBalancerAttributes: &elb.LoadBalancerAttributes{ 1252 CrossZoneLoadBalancing: &elb.CrossZoneLoadBalancing{ 1253 Enabled: aws.Bool(true), 1254 }, 1255 }, 1256 LoadBalancerName: aws.String("my-load-balancer"), 1257 } 1258 1259 result, err := svc.ModifyLoadBalancerAttributes(input) 1260 if err != nil { 1261 if aerr, ok := err.(awserr.Error); ok { 1262 switch aerr.Code() { 1263 case elb.ErrCodeAccessPointNotFoundException: 1264 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 1265 case elb.ErrCodeLoadBalancerAttributeNotFoundException: 1266 fmt.Println(elb.ErrCodeLoadBalancerAttributeNotFoundException, aerr.Error()) 1267 case elb.ErrCodeInvalidConfigurationRequestException: 1268 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1269 default: 1270 fmt.Println(aerr.Error()) 1271 } 1272 } else { 1273 // Print the error, cast err to awserr.Error to get the Code and 1274 // Message from an error. 1275 fmt.Println(err.Error()) 1276 } 1277 return 1278 } 1279 1280 fmt.Println(result) 1281 } 1282 1283 // To enable connection draining 1284 // 1285 // This example enables connection draining for the specified load balancer. 1286 func ExampleELB_ModifyLoadBalancerAttributes_shared01() { 1287 svc := elb.New(session.New()) 1288 input := &elb.ModifyLoadBalancerAttributesInput{ 1289 LoadBalancerAttributes: &elb.LoadBalancerAttributes{ 1290 ConnectionDraining: &elb.ConnectionDraining{ 1291 Enabled: aws.Bool(true), 1292 Timeout: aws.Int64(300), 1293 }, 1294 }, 1295 LoadBalancerName: aws.String("my-load-balancer"), 1296 } 1297 1298 result, err := svc.ModifyLoadBalancerAttributes(input) 1299 if err != nil { 1300 if aerr, ok := err.(awserr.Error); ok { 1301 switch aerr.Code() { 1302 case elb.ErrCodeAccessPointNotFoundException: 1303 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 1304 case elb.ErrCodeLoadBalancerAttributeNotFoundException: 1305 fmt.Println(elb.ErrCodeLoadBalancerAttributeNotFoundException, aerr.Error()) 1306 case elb.ErrCodeInvalidConfigurationRequestException: 1307 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1308 default: 1309 fmt.Println(aerr.Error()) 1310 } 1311 } else { 1312 // Print the error, cast err to awserr.Error to get the Code and 1313 // Message from an error. 1314 fmt.Println(err.Error()) 1315 } 1316 return 1317 } 1318 1319 fmt.Println(result) 1320 } 1321 1322 // To register instances with a load balancer 1323 // 1324 // This example registers the specified instance with the specified load balancer. 1325 func ExampleELB_RegisterInstancesWithLoadBalancer_shared00() { 1326 svc := elb.New(session.New()) 1327 input := &elb.RegisterInstancesWithLoadBalancerInput{ 1328 Instances: []*elb.Instance{ 1329 { 1330 InstanceId: aws.String("i-d6f6fae3"), 1331 }, 1332 }, 1333 LoadBalancerName: aws.String("my-load-balancer"), 1334 } 1335 1336 result, err := svc.RegisterInstancesWithLoadBalancer(input) 1337 if err != nil { 1338 if aerr, ok := err.(awserr.Error); ok { 1339 switch aerr.Code() { 1340 case elb.ErrCodeAccessPointNotFoundException: 1341 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 1342 case elb.ErrCodeInvalidEndPointException: 1343 fmt.Println(elb.ErrCodeInvalidEndPointException, aerr.Error()) 1344 default: 1345 fmt.Println(aerr.Error()) 1346 } 1347 } else { 1348 // Print the error, cast err to awserr.Error to get the Code and 1349 // Message from an error. 1350 fmt.Println(err.Error()) 1351 } 1352 return 1353 } 1354 1355 fmt.Println(result) 1356 } 1357 1358 // To remove tags from a load balancer 1359 // 1360 // This example removes the specified tag from the specified load balancer. 1361 func ExampleELB_RemoveTags_shared00() { 1362 svc := elb.New(session.New()) 1363 input := &elb.RemoveTagsInput{ 1364 LoadBalancerNames: []*string{ 1365 aws.String("my-load-balancer"), 1366 }, 1367 Tags: []*elb.TagKeyOnly{ 1368 { 1369 Key: aws.String("project"), 1370 }, 1371 }, 1372 } 1373 1374 result, err := svc.RemoveTags(input) 1375 if err != nil { 1376 if aerr, ok := err.(awserr.Error); ok { 1377 switch aerr.Code() { 1378 case elb.ErrCodeAccessPointNotFoundException: 1379 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 1380 default: 1381 fmt.Println(aerr.Error()) 1382 } 1383 } else { 1384 // Print the error, cast err to awserr.Error to get the Code and 1385 // Message from an error. 1386 fmt.Println(err.Error()) 1387 } 1388 return 1389 } 1390 1391 fmt.Println(result) 1392 } 1393 1394 // To update the SSL certificate for an HTTPS listener 1395 // 1396 // This example replaces the existing SSL certificate for the specified HTTPS listener. 1397 func ExampleELB_SetLoadBalancerListenerSSLCertificate_shared00() { 1398 svc := elb.New(session.New()) 1399 input := &elb.SetLoadBalancerListenerSSLCertificateInput{ 1400 LoadBalancerName: aws.String("my-load-balancer"), 1401 LoadBalancerPort: aws.Int64(443), 1402 SSLCertificateId: aws.String("arn:aws:iam::123456789012:server-certificate/new-server-cert"), 1403 } 1404 1405 result, err := svc.SetLoadBalancerListenerSSLCertificate(input) 1406 if err != nil { 1407 if aerr, ok := err.(awserr.Error); ok { 1408 switch aerr.Code() { 1409 case elb.ErrCodeCertificateNotFoundException: 1410 fmt.Println(elb.ErrCodeCertificateNotFoundException, aerr.Error()) 1411 case elb.ErrCodeAccessPointNotFoundException: 1412 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 1413 case elb.ErrCodeListenerNotFoundException: 1414 fmt.Println(elb.ErrCodeListenerNotFoundException, aerr.Error()) 1415 case elb.ErrCodeInvalidConfigurationRequestException: 1416 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1417 case elb.ErrCodeUnsupportedProtocolException: 1418 fmt.Println(elb.ErrCodeUnsupportedProtocolException, aerr.Error()) 1419 default: 1420 fmt.Println(aerr.Error()) 1421 } 1422 } else { 1423 // Print the error, cast err to awserr.Error to get the Code and 1424 // Message from an error. 1425 fmt.Println(err.Error()) 1426 } 1427 return 1428 } 1429 1430 fmt.Println(result) 1431 } 1432 1433 // To replace the policies associated with a port for a backend instance 1434 // 1435 // This example replaces the policies that are currently associated with the specified 1436 // port. 1437 func ExampleELB_SetLoadBalancerPoliciesForBackendServer_shared00() { 1438 svc := elb.New(session.New()) 1439 input := &elb.SetLoadBalancerPoliciesForBackendServerInput{ 1440 InstancePort: aws.Int64(80), 1441 LoadBalancerName: aws.String("my-load-balancer"), 1442 PolicyNames: []*string{ 1443 aws.String("my-ProxyProtocol-policy"), 1444 }, 1445 } 1446 1447 result, err := svc.SetLoadBalancerPoliciesForBackendServer(input) 1448 if err != nil { 1449 if aerr, ok := err.(awserr.Error); ok { 1450 switch aerr.Code() { 1451 case elb.ErrCodeAccessPointNotFoundException: 1452 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 1453 case elb.ErrCodePolicyNotFoundException: 1454 fmt.Println(elb.ErrCodePolicyNotFoundException, aerr.Error()) 1455 case elb.ErrCodeInvalidConfigurationRequestException: 1456 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1457 default: 1458 fmt.Println(aerr.Error()) 1459 } 1460 } else { 1461 // Print the error, cast err to awserr.Error to get the Code and 1462 // Message from an error. 1463 fmt.Println(err.Error()) 1464 } 1465 return 1466 } 1467 1468 fmt.Println(result) 1469 } 1470 1471 // To replace the policies associated with a listener 1472 // 1473 // This example replaces the policies that are currently associated with the specified 1474 // listener. 1475 func ExampleELB_SetLoadBalancerPoliciesOfListener_shared00() { 1476 svc := elb.New(session.New()) 1477 input := &elb.SetLoadBalancerPoliciesOfListenerInput{ 1478 LoadBalancerName: aws.String("my-load-balancer"), 1479 LoadBalancerPort: aws.Int64(80), 1480 PolicyNames: []*string{ 1481 aws.String("my-SSLNegotiation-policy"), 1482 }, 1483 } 1484 1485 result, err := svc.SetLoadBalancerPoliciesOfListener(input) 1486 if err != nil { 1487 if aerr, ok := err.(awserr.Error); ok { 1488 switch aerr.Code() { 1489 case elb.ErrCodeAccessPointNotFoundException: 1490 fmt.Println(elb.ErrCodeAccessPointNotFoundException, aerr.Error()) 1491 case elb.ErrCodePolicyNotFoundException: 1492 fmt.Println(elb.ErrCodePolicyNotFoundException, aerr.Error()) 1493 case elb.ErrCodeListenerNotFoundException: 1494 fmt.Println(elb.ErrCodeListenerNotFoundException, aerr.Error()) 1495 case elb.ErrCodeInvalidConfigurationRequestException: 1496 fmt.Println(elb.ErrCodeInvalidConfigurationRequestException, aerr.Error()) 1497 default: 1498 fmt.Println(aerr.Error()) 1499 } 1500 } else { 1501 // Print the error, cast err to awserr.Error to get the Code and 1502 // Message from an error. 1503 fmt.Println(err.Error()) 1504 } 1505 return 1506 } 1507 1508 fmt.Println(result) 1509 }