github.com/aavshr/aws-sdk-go@v1.41.3/service/organizations/examples_test.go (about) 1 // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 3 package organizations_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/organizations" 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 accept a handshake from another account 29 // 30 // Bill is the owner of an organization, and he invites Juan's account (222222222222) 31 // to join his organization. The following example shows Juan's account accepting the 32 // handshake and thus agreeing to the invitation. 33 func ExampleOrganizations_AcceptHandshake_shared00() { 34 svc := organizations.New(session.New()) 35 input := &organizations.AcceptHandshakeInput{ 36 HandshakeId: aws.String("h-examplehandshakeid111"), 37 } 38 39 result, err := svc.AcceptHandshake(input) 40 if err != nil { 41 if aerr, ok := err.(awserr.Error); ok { 42 switch aerr.Code() { 43 case organizations.ErrCodeAccessDeniedException: 44 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 45 case organizations.ErrCodeAWSOrganizationsNotInUseException: 46 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 47 case organizations.ErrCodeHandshakeConstraintViolationException: 48 fmt.Println(organizations.ErrCodeHandshakeConstraintViolationException, aerr.Error()) 49 case organizations.ErrCodeHandshakeNotFoundException: 50 fmt.Println(organizations.ErrCodeHandshakeNotFoundException, aerr.Error()) 51 case organizations.ErrCodeInvalidHandshakeTransitionException: 52 fmt.Println(organizations.ErrCodeInvalidHandshakeTransitionException, aerr.Error()) 53 case organizations.ErrCodeHandshakeAlreadyInStateException: 54 fmt.Println(organizations.ErrCodeHandshakeAlreadyInStateException, aerr.Error()) 55 case organizations.ErrCodeInvalidInputException: 56 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 57 case organizations.ErrCodeConcurrentModificationException: 58 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 59 case organizations.ErrCodeServiceException: 60 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 61 case organizations.ErrCodeTooManyRequestsException: 62 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 63 case organizations.ErrCodeAccessDeniedForDependencyException: 64 fmt.Println(organizations.ErrCodeAccessDeniedForDependencyException, aerr.Error()) 65 default: 66 fmt.Println(aerr.Error()) 67 } 68 } else { 69 // Print the error, cast err to awserr.Error to get the Code and 70 // Message from an error. 71 fmt.Println(err.Error()) 72 } 73 return 74 } 75 76 fmt.Println(result) 77 } 78 79 // To attach a policy to an OU 80 // 81 // The following example shows how to attach a service control policy (SCP) to an OU: 82 func ExampleOrganizations_AttachPolicy_shared00() { 83 svc := organizations.New(session.New()) 84 input := &organizations.AttachPolicyInput{ 85 PolicyId: aws.String("p-examplepolicyid111"), 86 TargetId: aws.String("ou-examplerootid111-exampleouid111"), 87 } 88 89 result, err := svc.AttachPolicy(input) 90 if err != nil { 91 if aerr, ok := err.(awserr.Error); ok { 92 switch aerr.Code() { 93 case organizations.ErrCodeAccessDeniedException: 94 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 95 case organizations.ErrCodeAWSOrganizationsNotInUseException: 96 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 97 case organizations.ErrCodeConcurrentModificationException: 98 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 99 case organizations.ErrCodeConstraintViolationException: 100 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 101 case organizations.ErrCodeDuplicatePolicyAttachmentException: 102 fmt.Println(organizations.ErrCodeDuplicatePolicyAttachmentException, aerr.Error()) 103 case organizations.ErrCodeInvalidInputException: 104 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 105 case organizations.ErrCodePolicyNotFoundException: 106 fmt.Println(organizations.ErrCodePolicyNotFoundException, aerr.Error()) 107 case organizations.ErrCodePolicyTypeNotEnabledException: 108 fmt.Println(organizations.ErrCodePolicyTypeNotEnabledException, aerr.Error()) 109 case organizations.ErrCodeServiceException: 110 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 111 case organizations.ErrCodeTargetNotFoundException: 112 fmt.Println(organizations.ErrCodeTargetNotFoundException, aerr.Error()) 113 case organizations.ErrCodeTooManyRequestsException: 114 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 115 case organizations.ErrCodeUnsupportedAPIEndpointException: 116 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 117 case organizations.ErrCodePolicyChangesInProgressException: 118 fmt.Println(organizations.ErrCodePolicyChangesInProgressException, aerr.Error()) 119 default: 120 fmt.Println(aerr.Error()) 121 } 122 } else { 123 // Print the error, cast err to awserr.Error to get the Code and 124 // Message from an error. 125 fmt.Println(err.Error()) 126 } 127 return 128 } 129 130 fmt.Println(result) 131 } 132 133 // To attach a policy to an account 134 // 135 // The following example shows how to attach a service control policy (SCP) to an account: 136 func ExampleOrganizations_AttachPolicy_shared01() { 137 svc := organizations.New(session.New()) 138 input := &organizations.AttachPolicyInput{ 139 PolicyId: aws.String("p-examplepolicyid111"), 140 TargetId: aws.String("333333333333"), 141 } 142 143 result, err := svc.AttachPolicy(input) 144 if err != nil { 145 if aerr, ok := err.(awserr.Error); ok { 146 switch aerr.Code() { 147 case organizations.ErrCodeAccessDeniedException: 148 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 149 case organizations.ErrCodeAWSOrganizationsNotInUseException: 150 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 151 case organizations.ErrCodeConcurrentModificationException: 152 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 153 case organizations.ErrCodeConstraintViolationException: 154 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 155 case organizations.ErrCodeDuplicatePolicyAttachmentException: 156 fmt.Println(organizations.ErrCodeDuplicatePolicyAttachmentException, aerr.Error()) 157 case organizations.ErrCodeInvalidInputException: 158 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 159 case organizations.ErrCodePolicyNotFoundException: 160 fmt.Println(organizations.ErrCodePolicyNotFoundException, aerr.Error()) 161 case organizations.ErrCodePolicyTypeNotEnabledException: 162 fmt.Println(organizations.ErrCodePolicyTypeNotEnabledException, aerr.Error()) 163 case organizations.ErrCodeServiceException: 164 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 165 case organizations.ErrCodeTargetNotFoundException: 166 fmt.Println(organizations.ErrCodeTargetNotFoundException, aerr.Error()) 167 case organizations.ErrCodeTooManyRequestsException: 168 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 169 case organizations.ErrCodeUnsupportedAPIEndpointException: 170 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 171 case organizations.ErrCodePolicyChangesInProgressException: 172 fmt.Println(organizations.ErrCodePolicyChangesInProgressException, aerr.Error()) 173 default: 174 fmt.Println(aerr.Error()) 175 } 176 } else { 177 // Print the error, cast err to awserr.Error to get the Code and 178 // Message from an error. 179 fmt.Println(err.Error()) 180 } 181 return 182 } 183 184 fmt.Println(result) 185 } 186 187 // To cancel a handshake sent to a member account 188 // 189 // Bill previously sent an invitation to Susan's account to join his organization. He 190 // changes his mind and decides to cancel the invitation before Susan accepts it. The 191 // following example shows Bill's cancellation: 192 func ExampleOrganizations_CancelHandshake_shared00() { 193 svc := organizations.New(session.New()) 194 input := &organizations.CancelHandshakeInput{ 195 HandshakeId: aws.String("h-examplehandshakeid111"), 196 } 197 198 result, err := svc.CancelHandshake(input) 199 if err != nil { 200 if aerr, ok := err.(awserr.Error); ok { 201 switch aerr.Code() { 202 case organizations.ErrCodeAccessDeniedException: 203 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 204 case organizations.ErrCodeConcurrentModificationException: 205 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 206 case organizations.ErrCodeHandshakeNotFoundException: 207 fmt.Println(organizations.ErrCodeHandshakeNotFoundException, aerr.Error()) 208 case organizations.ErrCodeInvalidHandshakeTransitionException: 209 fmt.Println(organizations.ErrCodeInvalidHandshakeTransitionException, aerr.Error()) 210 case organizations.ErrCodeHandshakeAlreadyInStateException: 211 fmt.Println(organizations.ErrCodeHandshakeAlreadyInStateException, aerr.Error()) 212 case organizations.ErrCodeInvalidInputException: 213 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 214 case organizations.ErrCodeServiceException: 215 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 216 case organizations.ErrCodeTooManyRequestsException: 217 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 218 default: 219 fmt.Println(aerr.Error()) 220 } 221 } else { 222 // Print the error, cast err to awserr.Error to get the Code and 223 // Message from an error. 224 fmt.Println(err.Error()) 225 } 226 return 227 } 228 229 fmt.Println(result) 230 } 231 232 // To create a new account that is automatically part of the organization 233 // 234 // The owner of an organization creates a member account in the organization. The following 235 // example shows that when the organization owner creates the member account, the account 236 // is preconfigured with the name "Production Account" and an owner email address of 237 // susan@example.com. An IAM role is automatically created using the default name because 238 // the roleName parameter is not used. AWS Organizations sends Susan a "Welcome to AWS" 239 // email: 240 func ExampleOrganizations_CreateAccount_shared00() { 241 svc := organizations.New(session.New()) 242 input := &organizations.CreateAccountInput{ 243 AccountName: aws.String("Production Account"), 244 Email: aws.String("susan@example.com"), 245 } 246 247 result, err := svc.CreateAccount(input) 248 if err != nil { 249 if aerr, ok := err.(awserr.Error); ok { 250 switch aerr.Code() { 251 case organizations.ErrCodeAccessDeniedException: 252 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 253 case organizations.ErrCodeAWSOrganizationsNotInUseException: 254 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 255 case organizations.ErrCodeConcurrentModificationException: 256 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 257 case organizations.ErrCodeConstraintViolationException: 258 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 259 case organizations.ErrCodeInvalidInputException: 260 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 261 case organizations.ErrCodeFinalizingOrganizationException: 262 fmt.Println(organizations.ErrCodeFinalizingOrganizationException, aerr.Error()) 263 case organizations.ErrCodeServiceException: 264 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 265 case organizations.ErrCodeTooManyRequestsException: 266 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 267 case organizations.ErrCodeUnsupportedAPIEndpointException: 268 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 269 default: 270 fmt.Println(aerr.Error()) 271 } 272 } else { 273 // Print the error, cast err to awserr.Error to get the Code and 274 // Message from an error. 275 fmt.Println(err.Error()) 276 } 277 return 278 } 279 280 fmt.Println(result) 281 } 282 283 // To create a new organization with all features enabled 284 // 285 // Bill wants to create an organization using credentials from account 111111111111. 286 // The following example shows that the account becomes the master account in the new 287 // organization. Because he does not specify a feature set, the new organization defaults 288 // to all features enabled and service control policies enabled on the root: 289 func ExampleOrganizations_CreateOrganization_shared00() { 290 svc := organizations.New(session.New()) 291 input := &organizations.CreateOrganizationInput{} 292 293 result, err := svc.CreateOrganization(input) 294 if err != nil { 295 if aerr, ok := err.(awserr.Error); ok { 296 switch aerr.Code() { 297 case organizations.ErrCodeAccessDeniedException: 298 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 299 case organizations.ErrCodeAlreadyInOrganizationException: 300 fmt.Println(organizations.ErrCodeAlreadyInOrganizationException, aerr.Error()) 301 case organizations.ErrCodeConcurrentModificationException: 302 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 303 case organizations.ErrCodeConstraintViolationException: 304 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 305 case organizations.ErrCodeInvalidInputException: 306 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 307 case organizations.ErrCodeServiceException: 308 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 309 case organizations.ErrCodeTooManyRequestsException: 310 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 311 case organizations.ErrCodeAccessDeniedForDependencyException: 312 fmt.Println(organizations.ErrCodeAccessDeniedForDependencyException, aerr.Error()) 313 default: 314 fmt.Println(aerr.Error()) 315 } 316 } else { 317 // Print the error, cast err to awserr.Error to get the Code and 318 // Message from an error. 319 fmt.Println(err.Error()) 320 } 321 return 322 } 323 324 fmt.Println(result) 325 } 326 327 // To create a new organization with consolidated billing features only 328 // 329 // In the following example, Bill creates an organization using credentials from account 330 // 111111111111, and configures the organization to support only the consolidated billing 331 // feature set: 332 func ExampleOrganizations_CreateOrganization_shared01() { 333 svc := organizations.New(session.New()) 334 input := &organizations.CreateOrganizationInput{ 335 FeatureSet: aws.String("CONSOLIDATED_BILLING"), 336 } 337 338 result, err := svc.CreateOrganization(input) 339 if err != nil { 340 if aerr, ok := err.(awserr.Error); ok { 341 switch aerr.Code() { 342 case organizations.ErrCodeAccessDeniedException: 343 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 344 case organizations.ErrCodeAlreadyInOrganizationException: 345 fmt.Println(organizations.ErrCodeAlreadyInOrganizationException, aerr.Error()) 346 case organizations.ErrCodeConcurrentModificationException: 347 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 348 case organizations.ErrCodeConstraintViolationException: 349 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 350 case organizations.ErrCodeInvalidInputException: 351 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 352 case organizations.ErrCodeServiceException: 353 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 354 case organizations.ErrCodeTooManyRequestsException: 355 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 356 case organizations.ErrCodeAccessDeniedForDependencyException: 357 fmt.Println(organizations.ErrCodeAccessDeniedForDependencyException, aerr.Error()) 358 default: 359 fmt.Println(aerr.Error()) 360 } 361 } else { 362 // Print the error, cast err to awserr.Error to get the Code and 363 // Message from an error. 364 fmt.Println(err.Error()) 365 } 366 return 367 } 368 369 fmt.Println(result) 370 } 371 372 // To create a new organization unit 373 // 374 // The following example shows how to create an OU that is named AccountingOU. The new 375 // OU is directly under the root.: 376 func ExampleOrganizations_CreateOrganizationalUnit_shared00() { 377 svc := organizations.New(session.New()) 378 input := &organizations.CreateOrganizationalUnitInput{ 379 Name: aws.String("AccountingOU"), 380 ParentId: aws.String("r-examplerootid111"), 381 } 382 383 result, err := svc.CreateOrganizationalUnit(input) 384 if err != nil { 385 if aerr, ok := err.(awserr.Error); ok { 386 switch aerr.Code() { 387 case organizations.ErrCodeAccessDeniedException: 388 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 389 case organizations.ErrCodeAWSOrganizationsNotInUseException: 390 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 391 case organizations.ErrCodeConcurrentModificationException: 392 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 393 case organizations.ErrCodeConstraintViolationException: 394 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 395 case organizations.ErrCodeDuplicateOrganizationalUnitException: 396 fmt.Println(organizations.ErrCodeDuplicateOrganizationalUnitException, aerr.Error()) 397 case organizations.ErrCodeInvalidInputException: 398 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 399 case organizations.ErrCodeParentNotFoundException: 400 fmt.Println(organizations.ErrCodeParentNotFoundException, aerr.Error()) 401 case organizations.ErrCodeServiceException: 402 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 403 case organizations.ErrCodeTooManyRequestsException: 404 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 405 default: 406 fmt.Println(aerr.Error()) 407 } 408 } else { 409 // Print the error, cast err to awserr.Error to get the Code and 410 // Message from an error. 411 fmt.Println(err.Error()) 412 } 413 return 414 } 415 416 fmt.Println(result) 417 } 418 419 // To create a service control policy 420 // 421 // The following example shows how to create a service control policy (SCP) that is 422 // named AllowAllS3Actions. The JSON string in the content parameter specifies the content 423 // in the policy. The parameter string is escaped with backslashes to ensure that the 424 // embedded double quotes in the JSON policy are treated as literals in the parameter, 425 // which itself is surrounded by double quotes: 426 func ExampleOrganizations_CreatePolicy_shared00() { 427 svc := organizations.New(session.New()) 428 input := &organizations.CreatePolicyInput{ 429 Content: aws.String("{\\\"Version\\\":\\\"2012-10-17\\\",\\\"Statement\\\":{\\\"Effect\\\":\\\"Allow\\\",\\\"Action\\\":\\\"s3:*\\\"}}"), 430 Description: aws.String("Enables admins of attached accounts to delegate all S3 permissions"), 431 Name: aws.String("AllowAllS3Actions"), 432 Type: aws.String("SERVICE_CONTROL_POLICY"), 433 } 434 435 result, err := svc.CreatePolicy(input) 436 if err != nil { 437 if aerr, ok := err.(awserr.Error); ok { 438 switch aerr.Code() { 439 case organizations.ErrCodeAccessDeniedException: 440 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 441 case organizations.ErrCodeAWSOrganizationsNotInUseException: 442 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 443 case organizations.ErrCodeConcurrentModificationException: 444 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 445 case organizations.ErrCodeConstraintViolationException: 446 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 447 case organizations.ErrCodeDuplicatePolicyException: 448 fmt.Println(organizations.ErrCodeDuplicatePolicyException, aerr.Error()) 449 case organizations.ErrCodeInvalidInputException: 450 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 451 case organizations.ErrCodeMalformedPolicyDocumentException: 452 fmt.Println(organizations.ErrCodeMalformedPolicyDocumentException, aerr.Error()) 453 case organizations.ErrCodePolicyTypeNotAvailableForOrganizationException: 454 fmt.Println(organizations.ErrCodePolicyTypeNotAvailableForOrganizationException, aerr.Error()) 455 case organizations.ErrCodeServiceException: 456 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 457 case organizations.ErrCodeTooManyRequestsException: 458 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 459 case organizations.ErrCodeUnsupportedAPIEndpointException: 460 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 461 default: 462 fmt.Println(aerr.Error()) 463 } 464 } else { 465 // Print the error, cast err to awserr.Error to get the Code and 466 // Message from an error. 467 fmt.Println(err.Error()) 468 } 469 return 470 } 471 472 fmt.Println(result) 473 } 474 475 // To decline a handshake sent from the master account 476 // 477 // The following example shows Susan declining an invitation to join Bill's organization. 478 // The DeclineHandshake operation returns a handshake object, showing that the state 479 // is now DECLINED: 480 func ExampleOrganizations_DeclineHandshake_shared00() { 481 svc := organizations.New(session.New()) 482 input := &organizations.DeclineHandshakeInput{ 483 HandshakeId: aws.String("h-examplehandshakeid111"), 484 } 485 486 result, err := svc.DeclineHandshake(input) 487 if err != nil { 488 if aerr, ok := err.(awserr.Error); ok { 489 switch aerr.Code() { 490 case organizations.ErrCodeAccessDeniedException: 491 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 492 case organizations.ErrCodeConcurrentModificationException: 493 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 494 case organizations.ErrCodeHandshakeNotFoundException: 495 fmt.Println(organizations.ErrCodeHandshakeNotFoundException, aerr.Error()) 496 case organizations.ErrCodeInvalidHandshakeTransitionException: 497 fmt.Println(organizations.ErrCodeInvalidHandshakeTransitionException, aerr.Error()) 498 case organizations.ErrCodeHandshakeAlreadyInStateException: 499 fmt.Println(organizations.ErrCodeHandshakeAlreadyInStateException, aerr.Error()) 500 case organizations.ErrCodeInvalidInputException: 501 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 502 case organizations.ErrCodeServiceException: 503 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 504 case organizations.ErrCodeTooManyRequestsException: 505 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 506 default: 507 fmt.Println(aerr.Error()) 508 } 509 } else { 510 // Print the error, cast err to awserr.Error to get the Code and 511 // Message from an error. 512 fmt.Println(err.Error()) 513 } 514 return 515 } 516 517 fmt.Println(result) 518 } 519 520 // To delete an organization unit 521 // 522 // The following example shows how to delete an OU. The example assumes that you previously 523 // removed all accounts and other OUs from the OU: 524 func ExampleOrganizations_DeleteOrganizationalUnit_shared00() { 525 svc := organizations.New(session.New()) 526 input := &organizations.DeleteOrganizationalUnitInput{ 527 OrganizationalUnitId: aws.String("ou-examplerootid111-exampleouid111"), 528 } 529 530 result, err := svc.DeleteOrganizationalUnit(input) 531 if err != nil { 532 if aerr, ok := err.(awserr.Error); ok { 533 switch aerr.Code() { 534 case organizations.ErrCodeAccessDeniedException: 535 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 536 case organizations.ErrCodeAWSOrganizationsNotInUseException: 537 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 538 case organizations.ErrCodeConcurrentModificationException: 539 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 540 case organizations.ErrCodeInvalidInputException: 541 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 542 case organizations.ErrCodeOrganizationalUnitNotEmptyException: 543 fmt.Println(organizations.ErrCodeOrganizationalUnitNotEmptyException, aerr.Error()) 544 case organizations.ErrCodeOrganizationalUnitNotFoundException: 545 fmt.Println(organizations.ErrCodeOrganizationalUnitNotFoundException, aerr.Error()) 546 case organizations.ErrCodeServiceException: 547 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 548 case organizations.ErrCodeTooManyRequestsException: 549 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 550 default: 551 fmt.Println(aerr.Error()) 552 } 553 } else { 554 // Print the error, cast err to awserr.Error to get the Code and 555 // Message from an error. 556 fmt.Println(err.Error()) 557 } 558 return 559 } 560 561 fmt.Println(result) 562 } 563 564 // To delete a policy 565 // 566 // The following example shows how to delete a policy from an organization. The example 567 // assumes that you previously detached the policy from all entities: 568 func ExampleOrganizations_DeletePolicy_shared00() { 569 svc := organizations.New(session.New()) 570 input := &organizations.DeletePolicyInput{ 571 PolicyId: aws.String("p-examplepolicyid111"), 572 } 573 574 result, err := svc.DeletePolicy(input) 575 if err != nil { 576 if aerr, ok := err.(awserr.Error); ok { 577 switch aerr.Code() { 578 case organizations.ErrCodeAccessDeniedException: 579 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 580 case organizations.ErrCodeAWSOrganizationsNotInUseException: 581 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 582 case organizations.ErrCodeConcurrentModificationException: 583 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 584 case organizations.ErrCodeInvalidInputException: 585 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 586 case organizations.ErrCodePolicyInUseException: 587 fmt.Println(organizations.ErrCodePolicyInUseException, aerr.Error()) 588 case organizations.ErrCodePolicyNotFoundException: 589 fmt.Println(organizations.ErrCodePolicyNotFoundException, aerr.Error()) 590 case organizations.ErrCodeServiceException: 591 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 592 case organizations.ErrCodeTooManyRequestsException: 593 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 594 case organizations.ErrCodeUnsupportedAPIEndpointException: 595 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 596 default: 597 fmt.Println(aerr.Error()) 598 } 599 } else { 600 // Print the error, cast err to awserr.Error to get the Code and 601 // Message from an error. 602 fmt.Println(err.Error()) 603 } 604 return 605 } 606 607 fmt.Println(result) 608 } 609 610 // To get the details about an account 611 // 612 // The following example shows a user in the master account (111111111111) asking for 613 // details about account 555555555555: 614 func ExampleOrganizations_DescribeAccount_shared00() { 615 svc := organizations.New(session.New()) 616 input := &organizations.DescribeAccountInput{ 617 AccountId: aws.String("555555555555"), 618 } 619 620 result, err := svc.DescribeAccount(input) 621 if err != nil { 622 if aerr, ok := err.(awserr.Error); ok { 623 switch aerr.Code() { 624 case organizations.ErrCodeAccessDeniedException: 625 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 626 case organizations.ErrCodeAccountNotFoundException: 627 fmt.Println(organizations.ErrCodeAccountNotFoundException, aerr.Error()) 628 case organizations.ErrCodeAWSOrganizationsNotInUseException: 629 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 630 case organizations.ErrCodeInvalidInputException: 631 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 632 case organizations.ErrCodeServiceException: 633 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 634 case organizations.ErrCodeTooManyRequestsException: 635 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 636 default: 637 fmt.Println(aerr.Error()) 638 } 639 } else { 640 // Print the error, cast err to awserr.Error to get the Code and 641 // Message from an error. 642 fmt.Println(err.Error()) 643 } 644 return 645 } 646 647 fmt.Println(result) 648 } 649 650 // To get information about a request to create an account 651 // 652 // The following example shows how to request the status about a previous request to 653 // create an account in an organization. This operation can be called only by a principal 654 // from the organization's master account. In the example, the specified "createAccountRequestId" 655 // comes from the response of the original call to "CreateAccount": 656 func ExampleOrganizations_DescribeCreateAccountStatus_shared00() { 657 svc := organizations.New(session.New()) 658 input := &organizations.DescribeCreateAccountStatusInput{ 659 CreateAccountRequestId: aws.String("car-exampleaccountcreationrequestid"), 660 } 661 662 result, err := svc.DescribeCreateAccountStatus(input) 663 if err != nil { 664 if aerr, ok := err.(awserr.Error); ok { 665 switch aerr.Code() { 666 case organizations.ErrCodeAccessDeniedException: 667 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 668 case organizations.ErrCodeAWSOrganizationsNotInUseException: 669 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 670 case organizations.ErrCodeCreateAccountStatusNotFoundException: 671 fmt.Println(organizations.ErrCodeCreateAccountStatusNotFoundException, aerr.Error()) 672 case organizations.ErrCodeInvalidInputException: 673 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 674 case organizations.ErrCodeServiceException: 675 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 676 case organizations.ErrCodeTooManyRequestsException: 677 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 678 case organizations.ErrCodeUnsupportedAPIEndpointException: 679 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 680 default: 681 fmt.Println(aerr.Error()) 682 } 683 } else { 684 // Print the error, cast err to awserr.Error to get the Code and 685 // Message from an error. 686 fmt.Println(err.Error()) 687 } 688 return 689 } 690 691 fmt.Println(result) 692 } 693 694 // To get information about a handshake 695 // 696 // The following example shows you how to request details about a handshake. The handshake 697 // ID comes either from the original call to "InviteAccountToOrganization", or from 698 // a call to "ListHandshakesForAccount" or "ListHandshakesForOrganization": 699 func ExampleOrganizations_DescribeHandshake_shared00() { 700 svc := organizations.New(session.New()) 701 input := &organizations.DescribeHandshakeInput{ 702 HandshakeId: aws.String("h-examplehandshakeid111"), 703 } 704 705 result, err := svc.DescribeHandshake(input) 706 if err != nil { 707 if aerr, ok := err.(awserr.Error); ok { 708 switch aerr.Code() { 709 case organizations.ErrCodeAccessDeniedException: 710 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 711 case organizations.ErrCodeConcurrentModificationException: 712 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 713 case organizations.ErrCodeHandshakeNotFoundException: 714 fmt.Println(organizations.ErrCodeHandshakeNotFoundException, aerr.Error()) 715 case organizations.ErrCodeInvalidInputException: 716 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 717 case organizations.ErrCodeServiceException: 718 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 719 case organizations.ErrCodeTooManyRequestsException: 720 fmt.Println(organizations.ErrCodeTooManyRequestsException, 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 get information about an organization 736 // 737 // The following example shows how to request information about the current user's organization:/n/n 738 func ExampleOrganizations_DescribeOrganization_shared00() { 739 svc := organizations.New(session.New()) 740 input := &organizations.DescribeOrganizationInput{} 741 742 result, err := svc.DescribeOrganization(input) 743 if err != nil { 744 if aerr, ok := err.(awserr.Error); ok { 745 switch aerr.Code() { 746 case organizations.ErrCodeAccessDeniedException: 747 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 748 case organizations.ErrCodeAWSOrganizationsNotInUseException: 749 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 750 case organizations.ErrCodeConcurrentModificationException: 751 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 752 case organizations.ErrCodeServiceException: 753 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 754 case organizations.ErrCodeTooManyRequestsException: 755 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 756 default: 757 fmt.Println(aerr.Error()) 758 } 759 } else { 760 // Print the error, cast err to awserr.Error to get the Code and 761 // Message from an error. 762 fmt.Println(err.Error()) 763 } 764 return 765 } 766 767 fmt.Println(result) 768 } 769 770 // To get information about an organizational unit 771 // 772 // The following example shows how to request details about an OU:/n/n 773 func ExampleOrganizations_DescribeOrganizationalUnit_shared00() { 774 svc := organizations.New(session.New()) 775 input := &organizations.DescribeOrganizationalUnitInput{ 776 OrganizationalUnitId: aws.String("ou-examplerootid111-exampleouid111"), 777 } 778 779 result, err := svc.DescribeOrganizationalUnit(input) 780 if err != nil { 781 if aerr, ok := err.(awserr.Error); ok { 782 switch aerr.Code() { 783 case organizations.ErrCodeAccessDeniedException: 784 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 785 case organizations.ErrCodeAWSOrganizationsNotInUseException: 786 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 787 case organizations.ErrCodeInvalidInputException: 788 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 789 case organizations.ErrCodeOrganizationalUnitNotFoundException: 790 fmt.Println(organizations.ErrCodeOrganizationalUnitNotFoundException, aerr.Error()) 791 case organizations.ErrCodeServiceException: 792 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 793 case organizations.ErrCodeTooManyRequestsException: 794 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 795 default: 796 fmt.Println(aerr.Error()) 797 } 798 } else { 799 // Print the error, cast err to awserr.Error to get the Code and 800 // Message from an error. 801 fmt.Println(err.Error()) 802 } 803 return 804 } 805 806 fmt.Println(result) 807 } 808 809 // To get information about a policy 810 // 811 // The following example shows how to request information about a policy:/n/n 812 func ExampleOrganizations_DescribePolicy_shared00() { 813 svc := organizations.New(session.New()) 814 input := &organizations.DescribePolicyInput{ 815 PolicyId: aws.String("p-examplepolicyid111"), 816 } 817 818 result, err := svc.DescribePolicy(input) 819 if err != nil { 820 if aerr, ok := err.(awserr.Error); ok { 821 switch aerr.Code() { 822 case organizations.ErrCodeAccessDeniedException: 823 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 824 case organizations.ErrCodeAWSOrganizationsNotInUseException: 825 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 826 case organizations.ErrCodeInvalidInputException: 827 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 828 case organizations.ErrCodePolicyNotFoundException: 829 fmt.Println(organizations.ErrCodePolicyNotFoundException, aerr.Error()) 830 case organizations.ErrCodeServiceException: 831 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 832 case organizations.ErrCodeTooManyRequestsException: 833 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 834 case organizations.ErrCodeUnsupportedAPIEndpointException: 835 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 836 default: 837 fmt.Println(aerr.Error()) 838 } 839 } else { 840 // Print the error, cast err to awserr.Error to get the Code and 841 // Message from an error. 842 fmt.Println(err.Error()) 843 } 844 return 845 } 846 847 fmt.Println(result) 848 } 849 850 // To detach a policy from a root, OU, or account 851 // 852 // The following example shows how to detach a policy from an OU:/n/n 853 func ExampleOrganizations_DetachPolicy_shared00() { 854 svc := organizations.New(session.New()) 855 input := &organizations.DetachPolicyInput{ 856 PolicyId: aws.String("p-examplepolicyid111"), 857 TargetId: aws.String("ou-examplerootid111-exampleouid111"), 858 } 859 860 result, err := svc.DetachPolicy(input) 861 if err != nil { 862 if aerr, ok := err.(awserr.Error); ok { 863 switch aerr.Code() { 864 case organizations.ErrCodeAccessDeniedException: 865 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 866 case organizations.ErrCodeAWSOrganizationsNotInUseException: 867 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 868 case organizations.ErrCodeConcurrentModificationException: 869 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 870 case organizations.ErrCodeConstraintViolationException: 871 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 872 case organizations.ErrCodeInvalidInputException: 873 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 874 case organizations.ErrCodePolicyNotAttachedException: 875 fmt.Println(organizations.ErrCodePolicyNotAttachedException, aerr.Error()) 876 case organizations.ErrCodePolicyNotFoundException: 877 fmt.Println(organizations.ErrCodePolicyNotFoundException, aerr.Error()) 878 case organizations.ErrCodeServiceException: 879 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 880 case organizations.ErrCodeTargetNotFoundException: 881 fmt.Println(organizations.ErrCodeTargetNotFoundException, aerr.Error()) 882 case organizations.ErrCodeTooManyRequestsException: 883 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 884 case organizations.ErrCodeUnsupportedAPIEndpointException: 885 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 886 case organizations.ErrCodePolicyChangesInProgressException: 887 fmt.Println(organizations.ErrCodePolicyChangesInProgressException, aerr.Error()) 888 default: 889 fmt.Println(aerr.Error()) 890 } 891 } else { 892 // Print the error, cast err to awserr.Error to get the Code and 893 // Message from an error. 894 fmt.Println(err.Error()) 895 } 896 return 897 } 898 899 fmt.Println(result) 900 } 901 902 // To disable a policy type in a root 903 // 904 // The following example shows how to disable the service control policy (SCP) policy 905 // type in a root. The response shows that the PolicyTypes response element no longer 906 // includes SERVICE_CONTROL_POLICY:/n/n 907 func ExampleOrganizations_DisablePolicyType_shared00() { 908 svc := organizations.New(session.New()) 909 input := &organizations.DisablePolicyTypeInput{ 910 PolicyType: aws.String("SERVICE_CONTROL_POLICY"), 911 RootId: aws.String("r-examplerootid111"), 912 } 913 914 result, err := svc.DisablePolicyType(input) 915 if err != nil { 916 if aerr, ok := err.(awserr.Error); ok { 917 switch aerr.Code() { 918 case organizations.ErrCodeAccessDeniedException: 919 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 920 case organizations.ErrCodeAWSOrganizationsNotInUseException: 921 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 922 case organizations.ErrCodeConcurrentModificationException: 923 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 924 case organizations.ErrCodeConstraintViolationException: 925 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 926 case organizations.ErrCodeInvalidInputException: 927 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 928 case organizations.ErrCodePolicyTypeNotEnabledException: 929 fmt.Println(organizations.ErrCodePolicyTypeNotEnabledException, aerr.Error()) 930 case organizations.ErrCodeRootNotFoundException: 931 fmt.Println(organizations.ErrCodeRootNotFoundException, aerr.Error()) 932 case organizations.ErrCodeServiceException: 933 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 934 case organizations.ErrCodeTooManyRequestsException: 935 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 936 case organizations.ErrCodeUnsupportedAPIEndpointException: 937 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 938 case organizations.ErrCodePolicyChangesInProgressException: 939 fmt.Println(organizations.ErrCodePolicyChangesInProgressException, aerr.Error()) 940 default: 941 fmt.Println(aerr.Error()) 942 } 943 } else { 944 // Print the error, cast err to awserr.Error to get the Code and 945 // Message from an error. 946 fmt.Println(err.Error()) 947 } 948 return 949 } 950 951 fmt.Println(result) 952 } 953 954 // To enable all features in an organization 955 // 956 // This example shows the administrator asking all the invited accounts in the organization 957 // to approve enabling all features in the organization. AWS Organizations sends an 958 // email to the address that is registered with every invited member account asking 959 // the owner to approve the change by accepting the handshake that is sent. After all 960 // invited member accounts accept the handshake, the organization administrator can 961 // finalize the change to enable all features, and those with appropriate permissions 962 // can create policies and apply them to roots, OUs, and accounts:/n/n 963 func ExampleOrganizations_EnableAllFeatures_shared00() { 964 svc := organizations.New(session.New()) 965 input := &organizations.EnableAllFeaturesInput{} 966 967 result, err := svc.EnableAllFeatures(input) 968 if err != nil { 969 if aerr, ok := err.(awserr.Error); ok { 970 switch aerr.Code() { 971 case organizations.ErrCodeAccessDeniedException: 972 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 973 case organizations.ErrCodeAWSOrganizationsNotInUseException: 974 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 975 case organizations.ErrCodeConcurrentModificationException: 976 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 977 case organizations.ErrCodeHandshakeConstraintViolationException: 978 fmt.Println(organizations.ErrCodeHandshakeConstraintViolationException, aerr.Error()) 979 case organizations.ErrCodeInvalidInputException: 980 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 981 case organizations.ErrCodeServiceException: 982 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 983 case organizations.ErrCodeTooManyRequestsException: 984 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 985 default: 986 fmt.Println(aerr.Error()) 987 } 988 } else { 989 // Print the error, cast err to awserr.Error to get the Code and 990 // Message from an error. 991 fmt.Println(err.Error()) 992 } 993 return 994 } 995 996 fmt.Println(result) 997 } 998 999 // To enable a policy type in a root 1000 // 1001 // The following example shows how to enable the service control policy (SCP) policy 1002 // type in a root. The output shows a root object with a PolicyTypes response element 1003 // showing that SCPs are now enabled:/n/n 1004 func ExampleOrganizations_EnablePolicyType_shared00() { 1005 svc := organizations.New(session.New()) 1006 input := &organizations.EnablePolicyTypeInput{ 1007 PolicyType: aws.String("SERVICE_CONTROL_POLICY"), 1008 RootId: aws.String("r-examplerootid111"), 1009 } 1010 1011 result, err := svc.EnablePolicyType(input) 1012 if err != nil { 1013 if aerr, ok := err.(awserr.Error); ok { 1014 switch aerr.Code() { 1015 case organizations.ErrCodeAccessDeniedException: 1016 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1017 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1018 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1019 case organizations.ErrCodeConcurrentModificationException: 1020 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 1021 case organizations.ErrCodeConstraintViolationException: 1022 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 1023 case organizations.ErrCodeInvalidInputException: 1024 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1025 case organizations.ErrCodePolicyTypeAlreadyEnabledException: 1026 fmt.Println(organizations.ErrCodePolicyTypeAlreadyEnabledException, aerr.Error()) 1027 case organizations.ErrCodeRootNotFoundException: 1028 fmt.Println(organizations.ErrCodeRootNotFoundException, aerr.Error()) 1029 case organizations.ErrCodeServiceException: 1030 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1031 case organizations.ErrCodeTooManyRequestsException: 1032 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1033 case organizations.ErrCodePolicyTypeNotAvailableForOrganizationException: 1034 fmt.Println(organizations.ErrCodePolicyTypeNotAvailableForOrganizationException, aerr.Error()) 1035 case organizations.ErrCodeUnsupportedAPIEndpointException: 1036 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 1037 case organizations.ErrCodePolicyChangesInProgressException: 1038 fmt.Println(organizations.ErrCodePolicyChangesInProgressException, aerr.Error()) 1039 default: 1040 fmt.Println(aerr.Error()) 1041 } 1042 } else { 1043 // Print the error, cast err to awserr.Error to get the Code and 1044 // Message from an error. 1045 fmt.Println(err.Error()) 1046 } 1047 return 1048 } 1049 1050 fmt.Println(result) 1051 } 1052 1053 // To invite an account to join an organization 1054 // 1055 // The following example shows the admin of the master account owned by bill@example.com 1056 // inviting the account owned by juan@example.com to join an organization. 1057 func ExampleOrganizations_InviteAccountToOrganization_shared00() { 1058 svc := organizations.New(session.New()) 1059 input := &organizations.InviteAccountToOrganizationInput{ 1060 Notes: aws.String("This is a request for Juan's account to join Bill's organization"), 1061 Target: &organizations.HandshakeParty{ 1062 Id: aws.String("juan@example.com"), 1063 Type: aws.String("EMAIL"), 1064 }, 1065 } 1066 1067 result, err := svc.InviteAccountToOrganization(input) 1068 if err != nil { 1069 if aerr, ok := err.(awserr.Error); ok { 1070 switch aerr.Code() { 1071 case organizations.ErrCodeAccessDeniedException: 1072 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1073 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1074 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1075 case organizations.ErrCodeAccountOwnerNotVerifiedException: 1076 fmt.Println(organizations.ErrCodeAccountOwnerNotVerifiedException, aerr.Error()) 1077 case organizations.ErrCodeConcurrentModificationException: 1078 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 1079 case organizations.ErrCodeHandshakeConstraintViolationException: 1080 fmt.Println(organizations.ErrCodeHandshakeConstraintViolationException, aerr.Error()) 1081 case organizations.ErrCodeDuplicateHandshakeException: 1082 fmt.Println(organizations.ErrCodeDuplicateHandshakeException, aerr.Error()) 1083 case organizations.ErrCodeConstraintViolationException: 1084 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 1085 case organizations.ErrCodeInvalidInputException: 1086 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1087 case organizations.ErrCodeFinalizingOrganizationException: 1088 fmt.Println(organizations.ErrCodeFinalizingOrganizationException, aerr.Error()) 1089 case organizations.ErrCodeServiceException: 1090 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1091 case organizations.ErrCodeTooManyRequestsException: 1092 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1093 default: 1094 fmt.Println(aerr.Error()) 1095 } 1096 } else { 1097 // Print the error, cast err to awserr.Error to get the Code and 1098 // Message from an error. 1099 fmt.Println(err.Error()) 1100 } 1101 return 1102 } 1103 1104 fmt.Println(result) 1105 } 1106 1107 // To leave an organization as a member account 1108 // 1109 // TThe following example shows how to remove your member account from an organization: 1110 func ExampleOrganizations_LeaveOrganization_shared00() { 1111 svc := organizations.New(session.New()) 1112 input := &organizations.LeaveOrganizationInput{} 1113 1114 result, err := svc.LeaveOrganization(input) 1115 if err != nil { 1116 if aerr, ok := err.(awserr.Error); ok { 1117 switch aerr.Code() { 1118 case organizations.ErrCodeAccessDeniedException: 1119 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1120 case organizations.ErrCodeAccountNotFoundException: 1121 fmt.Println(organizations.ErrCodeAccountNotFoundException, aerr.Error()) 1122 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1123 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1124 case organizations.ErrCodeConcurrentModificationException: 1125 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 1126 case organizations.ErrCodeConstraintViolationException: 1127 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 1128 case organizations.ErrCodeInvalidInputException: 1129 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1130 case organizations.ErrCodeMasterCannotLeaveOrganizationException: 1131 fmt.Println(organizations.ErrCodeMasterCannotLeaveOrganizationException, aerr.Error()) 1132 case organizations.ErrCodeServiceException: 1133 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1134 case organizations.ErrCodeTooManyRequestsException: 1135 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1136 default: 1137 fmt.Println(aerr.Error()) 1138 } 1139 } else { 1140 // Print the error, cast err to awserr.Error to get the Code and 1141 // Message from an error. 1142 fmt.Println(err.Error()) 1143 } 1144 return 1145 } 1146 1147 fmt.Println(result) 1148 } 1149 1150 // To retrieve a list of all of the accounts in an organization 1151 // 1152 // The following example shows you how to request a list of the accounts in an organization: 1153 func ExampleOrganizations_ListAccounts_shared00() { 1154 svc := organizations.New(session.New()) 1155 input := &organizations.ListAccountsInput{} 1156 1157 result, err := svc.ListAccounts(input) 1158 if err != nil { 1159 if aerr, ok := err.(awserr.Error); ok { 1160 switch aerr.Code() { 1161 case organizations.ErrCodeAccessDeniedException: 1162 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1163 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1164 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1165 case organizations.ErrCodeInvalidInputException: 1166 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1167 case organizations.ErrCodeServiceException: 1168 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1169 case organizations.ErrCodeTooManyRequestsException: 1170 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1171 default: 1172 fmt.Println(aerr.Error()) 1173 } 1174 } else { 1175 // Print the error, cast err to awserr.Error to get the Code and 1176 // Message from an error. 1177 fmt.Println(err.Error()) 1178 } 1179 return 1180 } 1181 1182 fmt.Println(result) 1183 } 1184 1185 // To retrieve a list of all of the accounts in a root or OU 1186 // 1187 // The following example shows how to request a list of the accounts in an OU:/n/n 1188 func ExampleOrganizations_ListAccountsForParent_shared00() { 1189 svc := organizations.New(session.New()) 1190 input := &organizations.ListAccountsForParentInput{ 1191 ParentId: aws.String("ou-examplerootid111-exampleouid111"), 1192 } 1193 1194 result, err := svc.ListAccountsForParent(input) 1195 if err != nil { 1196 if aerr, ok := err.(awserr.Error); ok { 1197 switch aerr.Code() { 1198 case organizations.ErrCodeAccessDeniedException: 1199 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1200 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1201 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1202 case organizations.ErrCodeInvalidInputException: 1203 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1204 case organizations.ErrCodeParentNotFoundException: 1205 fmt.Println(organizations.ErrCodeParentNotFoundException, aerr.Error()) 1206 case organizations.ErrCodeServiceException: 1207 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1208 case organizations.ErrCodeTooManyRequestsException: 1209 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1210 default: 1211 fmt.Println(aerr.Error()) 1212 } 1213 } else { 1214 // Print the error, cast err to awserr.Error to get the Code and 1215 // Message from an error. 1216 fmt.Println(err.Error()) 1217 } 1218 return 1219 } 1220 1221 fmt.Println(result) 1222 } 1223 1224 // To retrieve a list of all of the child accounts and OUs in a parent root or OU 1225 // 1226 // The following example shows how to request a list of the child OUs in a parent root 1227 // or OU:/n/n 1228 func ExampleOrganizations_ListChildren_shared00() { 1229 svc := organizations.New(session.New()) 1230 input := &organizations.ListChildrenInput{ 1231 ChildType: aws.String("ORGANIZATIONAL_UNIT"), 1232 ParentId: aws.String("ou-examplerootid111-exampleouid111"), 1233 } 1234 1235 result, err := svc.ListChildren(input) 1236 if err != nil { 1237 if aerr, ok := err.(awserr.Error); ok { 1238 switch aerr.Code() { 1239 case organizations.ErrCodeAccessDeniedException: 1240 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1241 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1242 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1243 case organizations.ErrCodeInvalidInputException: 1244 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1245 case organizations.ErrCodeParentNotFoundException: 1246 fmt.Println(organizations.ErrCodeParentNotFoundException, aerr.Error()) 1247 case organizations.ErrCodeServiceException: 1248 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1249 case organizations.ErrCodeTooManyRequestsException: 1250 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1251 default: 1252 fmt.Println(aerr.Error()) 1253 } 1254 } else { 1255 // Print the error, cast err to awserr.Error to get the Code and 1256 // Message from an error. 1257 fmt.Println(err.Error()) 1258 } 1259 return 1260 } 1261 1262 fmt.Println(result) 1263 } 1264 1265 // To get a list of completed account creation requests made in the organization 1266 // 1267 // The following example shows a user requesting a list of only the completed account 1268 // creation requests made for the current organization: 1269 func ExampleOrganizations_ListCreateAccountStatus_shared00() { 1270 svc := organizations.New(session.New()) 1271 input := &organizations.ListCreateAccountStatusInput{ 1272 States: []*string{ 1273 aws.String("SUCCEEDED"), 1274 }, 1275 } 1276 1277 result, err := svc.ListCreateAccountStatus(input) 1278 if err != nil { 1279 if aerr, ok := err.(awserr.Error); ok { 1280 switch aerr.Code() { 1281 case organizations.ErrCodeAccessDeniedException: 1282 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1283 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1284 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1285 case organizations.ErrCodeInvalidInputException: 1286 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1287 case organizations.ErrCodeServiceException: 1288 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1289 case organizations.ErrCodeTooManyRequestsException: 1290 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1291 case organizations.ErrCodeUnsupportedAPIEndpointException: 1292 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 1293 default: 1294 fmt.Println(aerr.Error()) 1295 } 1296 } else { 1297 // Print the error, cast err to awserr.Error to get the Code and 1298 // Message from an error. 1299 fmt.Println(err.Error()) 1300 } 1301 return 1302 } 1303 1304 fmt.Println(result) 1305 } 1306 1307 // To get a list of all account creation requests made in the organization 1308 // 1309 // The following example shows a user requesting a list of only the in-progress account 1310 // creation requests made for the current organization: 1311 func ExampleOrganizations_ListCreateAccountStatus_shared01() { 1312 svc := organizations.New(session.New()) 1313 input := &organizations.ListCreateAccountStatusInput{ 1314 States: []*string{ 1315 aws.String("IN_PROGRESS"), 1316 }, 1317 } 1318 1319 result, err := svc.ListCreateAccountStatus(input) 1320 if err != nil { 1321 if aerr, ok := err.(awserr.Error); ok { 1322 switch aerr.Code() { 1323 case organizations.ErrCodeAccessDeniedException: 1324 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1325 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1326 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1327 case organizations.ErrCodeInvalidInputException: 1328 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1329 case organizations.ErrCodeServiceException: 1330 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1331 case organizations.ErrCodeTooManyRequestsException: 1332 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1333 case organizations.ErrCodeUnsupportedAPIEndpointException: 1334 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 1335 default: 1336 fmt.Println(aerr.Error()) 1337 } 1338 } else { 1339 // Print the error, cast err to awserr.Error to get the Code and 1340 // Message from an error. 1341 fmt.Println(err.Error()) 1342 } 1343 return 1344 } 1345 1346 fmt.Println(result) 1347 } 1348 1349 // To retrieve a list of the handshakes sent to an account 1350 // 1351 // The following example shows you how to get a list of handshakes that are associated 1352 // with the account of the credentials used to call the operation: 1353 func ExampleOrganizations_ListHandshakesForAccount_shared00() { 1354 svc := organizations.New(session.New()) 1355 input := &organizations.ListHandshakesForAccountInput{} 1356 1357 result, err := svc.ListHandshakesForAccount(input) 1358 if err != nil { 1359 if aerr, ok := err.(awserr.Error); ok { 1360 switch aerr.Code() { 1361 case organizations.ErrCodeAccessDeniedException: 1362 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1363 case organizations.ErrCodeConcurrentModificationException: 1364 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 1365 case organizations.ErrCodeInvalidInputException: 1366 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1367 case organizations.ErrCodeServiceException: 1368 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1369 case organizations.ErrCodeTooManyRequestsException: 1370 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1371 default: 1372 fmt.Println(aerr.Error()) 1373 } 1374 } else { 1375 // Print the error, cast err to awserr.Error to get the Code and 1376 // Message from an error. 1377 fmt.Println(err.Error()) 1378 } 1379 return 1380 } 1381 1382 fmt.Println(result) 1383 } 1384 1385 // To retrieve a list of the handshakes associated with an organization 1386 // 1387 // The following example shows you how to get a list of handshakes associated with the 1388 // current organization: 1389 func ExampleOrganizations_ListHandshakesForOrganization_shared00() { 1390 svc := organizations.New(session.New()) 1391 input := &organizations.ListHandshakesForOrganizationInput{} 1392 1393 result, err := svc.ListHandshakesForOrganization(input) 1394 if err != nil { 1395 if aerr, ok := err.(awserr.Error); ok { 1396 switch aerr.Code() { 1397 case organizations.ErrCodeAccessDeniedException: 1398 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1399 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1400 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1401 case organizations.ErrCodeConcurrentModificationException: 1402 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 1403 case organizations.ErrCodeInvalidInputException: 1404 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1405 case organizations.ErrCodeServiceException: 1406 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1407 case organizations.ErrCodeTooManyRequestsException: 1408 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1409 default: 1410 fmt.Println(aerr.Error()) 1411 } 1412 } else { 1413 // Print the error, cast err to awserr.Error to get the Code and 1414 // Message from an error. 1415 fmt.Println(err.Error()) 1416 } 1417 return 1418 } 1419 1420 fmt.Println(result) 1421 } 1422 1423 // To retrieve a list of all of the child OUs in a parent root or OU 1424 // 1425 // The following example shows how to get a list of OUs in a specified root:/n/n 1426 func ExampleOrganizations_ListOrganizationalUnitsForParent_shared00() { 1427 svc := organizations.New(session.New()) 1428 input := &organizations.ListOrganizationalUnitsForParentInput{ 1429 ParentId: aws.String("r-examplerootid111"), 1430 } 1431 1432 result, err := svc.ListOrganizationalUnitsForParent(input) 1433 if err != nil { 1434 if aerr, ok := err.(awserr.Error); ok { 1435 switch aerr.Code() { 1436 case organizations.ErrCodeAccessDeniedException: 1437 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1438 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1439 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1440 case organizations.ErrCodeInvalidInputException: 1441 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1442 case organizations.ErrCodeParentNotFoundException: 1443 fmt.Println(organizations.ErrCodeParentNotFoundException, aerr.Error()) 1444 case organizations.ErrCodeServiceException: 1445 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1446 case organizations.ErrCodeTooManyRequestsException: 1447 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1448 default: 1449 fmt.Println(aerr.Error()) 1450 } 1451 } else { 1452 // Print the error, cast err to awserr.Error to get the Code and 1453 // Message from an error. 1454 fmt.Println(err.Error()) 1455 } 1456 return 1457 } 1458 1459 fmt.Println(result) 1460 } 1461 1462 // To retrieve a list of all of the parents of a child OU or account 1463 // 1464 // The following example shows how to list the root or OUs that contain account 444444444444:/n/n 1465 func ExampleOrganizations_ListParents_shared00() { 1466 svc := organizations.New(session.New()) 1467 input := &organizations.ListParentsInput{ 1468 ChildId: aws.String("444444444444"), 1469 } 1470 1471 result, err := svc.ListParents(input) 1472 if err != nil { 1473 if aerr, ok := err.(awserr.Error); ok { 1474 switch aerr.Code() { 1475 case organizations.ErrCodeAccessDeniedException: 1476 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1477 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1478 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1479 case organizations.ErrCodeChildNotFoundException: 1480 fmt.Println(organizations.ErrCodeChildNotFoundException, aerr.Error()) 1481 case organizations.ErrCodeInvalidInputException: 1482 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1483 case organizations.ErrCodeServiceException: 1484 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1485 case organizations.ErrCodeTooManyRequestsException: 1486 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1487 default: 1488 fmt.Println(aerr.Error()) 1489 } 1490 } else { 1491 // Print the error, cast err to awserr.Error to get the Code and 1492 // Message from an error. 1493 fmt.Println(err.Error()) 1494 } 1495 return 1496 } 1497 1498 fmt.Println(result) 1499 } 1500 1501 // To retrieve a list policies in the organization 1502 // 1503 // The following example shows how to get a list of service control policies (SCPs):/n/n 1504 func ExampleOrganizations_ListPolicies_shared00() { 1505 svc := organizations.New(session.New()) 1506 input := &organizations.ListPoliciesInput{ 1507 Filter: aws.String("SERVICE_CONTROL_POLICY"), 1508 } 1509 1510 result, err := svc.ListPolicies(input) 1511 if err != nil { 1512 if aerr, ok := err.(awserr.Error); ok { 1513 switch aerr.Code() { 1514 case organizations.ErrCodeAccessDeniedException: 1515 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1516 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1517 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1518 case organizations.ErrCodeInvalidInputException: 1519 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1520 case organizations.ErrCodeServiceException: 1521 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1522 case organizations.ErrCodeTooManyRequestsException: 1523 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1524 case organizations.ErrCodeUnsupportedAPIEndpointException: 1525 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 1526 default: 1527 fmt.Println(aerr.Error()) 1528 } 1529 } else { 1530 // Print the error, cast err to awserr.Error to get the Code and 1531 // Message from an error. 1532 fmt.Println(err.Error()) 1533 } 1534 return 1535 } 1536 1537 fmt.Println(result) 1538 } 1539 1540 // To retrieve a list policies attached to a root, OU, or account 1541 // 1542 // The following example shows how to get a list of all service control policies (SCPs) 1543 // of the type specified by the Filter parameter, that are directly attached to an account. 1544 // The returned list does not include policies that apply to the account because of 1545 // inheritance from its location in an OU hierarchy:/n/n 1546 func ExampleOrganizations_ListPoliciesForTarget_shared00() { 1547 svc := organizations.New(session.New()) 1548 input := &organizations.ListPoliciesForTargetInput{ 1549 Filter: aws.String("SERVICE_CONTROL_POLICY"), 1550 TargetId: aws.String("444444444444"), 1551 } 1552 1553 result, err := svc.ListPoliciesForTarget(input) 1554 if err != nil { 1555 if aerr, ok := err.(awserr.Error); ok { 1556 switch aerr.Code() { 1557 case organizations.ErrCodeAccessDeniedException: 1558 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1559 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1560 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1561 case organizations.ErrCodeInvalidInputException: 1562 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1563 case organizations.ErrCodeServiceException: 1564 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1565 case organizations.ErrCodeTargetNotFoundException: 1566 fmt.Println(organizations.ErrCodeTargetNotFoundException, aerr.Error()) 1567 case organizations.ErrCodeTooManyRequestsException: 1568 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1569 case organizations.ErrCodeUnsupportedAPIEndpointException: 1570 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 1571 default: 1572 fmt.Println(aerr.Error()) 1573 } 1574 } else { 1575 // Print the error, cast err to awserr.Error to get the Code and 1576 // Message from an error. 1577 fmt.Println(err.Error()) 1578 } 1579 return 1580 } 1581 1582 fmt.Println(result) 1583 } 1584 1585 // To retrieve a list of roots in the organization 1586 // 1587 // The following example shows how to get the list of the roots in the current organization:/n/n 1588 func ExampleOrganizations_ListRoots_shared00() { 1589 svc := organizations.New(session.New()) 1590 input := &organizations.ListRootsInput{} 1591 1592 result, err := svc.ListRoots(input) 1593 if err != nil { 1594 if aerr, ok := err.(awserr.Error); ok { 1595 switch aerr.Code() { 1596 case organizations.ErrCodeAccessDeniedException: 1597 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1598 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1599 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1600 case organizations.ErrCodeInvalidInputException: 1601 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1602 case organizations.ErrCodeServiceException: 1603 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1604 case organizations.ErrCodeTooManyRequestsException: 1605 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1606 default: 1607 fmt.Println(aerr.Error()) 1608 } 1609 } else { 1610 // Print the error, cast err to awserr.Error to get the Code and 1611 // Message from an error. 1612 fmt.Println(err.Error()) 1613 } 1614 return 1615 } 1616 1617 fmt.Println(result) 1618 } 1619 1620 // To retrieve a list of roots, OUs, and accounts to which a policy is attached 1621 // 1622 // The following example shows how to get the list of roots, OUs, and accounts to which 1623 // the specified policy is attached:/n/n 1624 func ExampleOrganizations_ListTargetsForPolicy_shared00() { 1625 svc := organizations.New(session.New()) 1626 input := &organizations.ListTargetsForPolicyInput{ 1627 PolicyId: aws.String("p-FullAWSAccess"), 1628 } 1629 1630 result, err := svc.ListTargetsForPolicy(input) 1631 if err != nil { 1632 if aerr, ok := err.(awserr.Error); ok { 1633 switch aerr.Code() { 1634 case organizations.ErrCodeAccessDeniedException: 1635 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1636 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1637 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1638 case organizations.ErrCodeInvalidInputException: 1639 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1640 case organizations.ErrCodePolicyNotFoundException: 1641 fmt.Println(organizations.ErrCodePolicyNotFoundException, aerr.Error()) 1642 case organizations.ErrCodeServiceException: 1643 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1644 case organizations.ErrCodeTooManyRequestsException: 1645 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1646 case organizations.ErrCodeUnsupportedAPIEndpointException: 1647 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 1648 default: 1649 fmt.Println(aerr.Error()) 1650 } 1651 } else { 1652 // Print the error, cast err to awserr.Error to get the Code and 1653 // Message from an error. 1654 fmt.Println(err.Error()) 1655 } 1656 return 1657 } 1658 1659 fmt.Println(result) 1660 } 1661 1662 // To move an OU or account to another OU or the root 1663 // 1664 // The following example shows how to move a member account from the root to an OU:/n/n 1665 func ExampleOrganizations_MoveAccount_shared00() { 1666 svc := organizations.New(session.New()) 1667 input := &organizations.MoveAccountInput{ 1668 AccountId: aws.String("333333333333"), 1669 DestinationParentId: aws.String("ou-examplerootid111-exampleouid111"), 1670 SourceParentId: aws.String("r-examplerootid111"), 1671 } 1672 1673 result, err := svc.MoveAccount(input) 1674 if err != nil { 1675 if aerr, ok := err.(awserr.Error); ok { 1676 switch aerr.Code() { 1677 case organizations.ErrCodeAccessDeniedException: 1678 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1679 case organizations.ErrCodeInvalidInputException: 1680 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1681 case organizations.ErrCodeSourceParentNotFoundException: 1682 fmt.Println(organizations.ErrCodeSourceParentNotFoundException, aerr.Error()) 1683 case organizations.ErrCodeDestinationParentNotFoundException: 1684 fmt.Println(organizations.ErrCodeDestinationParentNotFoundException, aerr.Error()) 1685 case organizations.ErrCodeDuplicateAccountException: 1686 fmt.Println(organizations.ErrCodeDuplicateAccountException, aerr.Error()) 1687 case organizations.ErrCodeAccountNotFoundException: 1688 fmt.Println(organizations.ErrCodeAccountNotFoundException, aerr.Error()) 1689 case organizations.ErrCodeTooManyRequestsException: 1690 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1691 case organizations.ErrCodeConcurrentModificationException: 1692 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 1693 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1694 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1695 case organizations.ErrCodeServiceException: 1696 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1697 default: 1698 fmt.Println(aerr.Error()) 1699 } 1700 } else { 1701 // Print the error, cast err to awserr.Error to get the Code and 1702 // Message from an error. 1703 fmt.Println(err.Error()) 1704 } 1705 return 1706 } 1707 1708 fmt.Println(result) 1709 } 1710 1711 // To remove an account from an organization as the master account 1712 // 1713 // The following example shows you how to remove an account from an organization: 1714 func ExampleOrganizations_RemoveAccountFromOrganization_shared00() { 1715 svc := organizations.New(session.New()) 1716 input := &organizations.RemoveAccountFromOrganizationInput{ 1717 AccountId: aws.String("333333333333"), 1718 } 1719 1720 result, err := svc.RemoveAccountFromOrganization(input) 1721 if err != nil { 1722 if aerr, ok := err.(awserr.Error); ok { 1723 switch aerr.Code() { 1724 case organizations.ErrCodeAccessDeniedException: 1725 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1726 case organizations.ErrCodeAccountNotFoundException: 1727 fmt.Println(organizations.ErrCodeAccountNotFoundException, aerr.Error()) 1728 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1729 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1730 case organizations.ErrCodeConcurrentModificationException: 1731 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 1732 case organizations.ErrCodeConstraintViolationException: 1733 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 1734 case organizations.ErrCodeInvalidInputException: 1735 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1736 case organizations.ErrCodeMasterCannotLeaveOrganizationException: 1737 fmt.Println(organizations.ErrCodeMasterCannotLeaveOrganizationException, aerr.Error()) 1738 case organizations.ErrCodeServiceException: 1739 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1740 case organizations.ErrCodeTooManyRequestsException: 1741 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1742 default: 1743 fmt.Println(aerr.Error()) 1744 } 1745 } else { 1746 // Print the error, cast err to awserr.Error to get the Code and 1747 // Message from an error. 1748 fmt.Println(err.Error()) 1749 } 1750 return 1751 } 1752 1753 fmt.Println(result) 1754 } 1755 1756 // To rename an organizational unit 1757 // 1758 // The following example shows how to rename an OU. The output confirms the new name:/n/n 1759 func ExampleOrganizations_UpdateOrganizationalUnit_shared00() { 1760 svc := organizations.New(session.New()) 1761 input := &organizations.UpdateOrganizationalUnitInput{ 1762 Name: aws.String("AccountingOU"), 1763 OrganizationalUnitId: aws.String("ou-examplerootid111-exampleouid111"), 1764 } 1765 1766 result, err := svc.UpdateOrganizationalUnit(input) 1767 if err != nil { 1768 if aerr, ok := err.(awserr.Error); ok { 1769 switch aerr.Code() { 1770 case organizations.ErrCodeAccessDeniedException: 1771 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1772 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1773 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1774 case organizations.ErrCodeConcurrentModificationException: 1775 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 1776 case organizations.ErrCodeDuplicateOrganizationalUnitException: 1777 fmt.Println(organizations.ErrCodeDuplicateOrganizationalUnitException, aerr.Error()) 1778 case organizations.ErrCodeInvalidInputException: 1779 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1780 case organizations.ErrCodeOrganizationalUnitNotFoundException: 1781 fmt.Println(organizations.ErrCodeOrganizationalUnitNotFoundException, aerr.Error()) 1782 case organizations.ErrCodeServiceException: 1783 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1784 case organizations.ErrCodeTooManyRequestsException: 1785 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1786 default: 1787 fmt.Println(aerr.Error()) 1788 } 1789 } else { 1790 // Print the error, cast err to awserr.Error to get the Code and 1791 // Message from an error. 1792 fmt.Println(err.Error()) 1793 } 1794 return 1795 } 1796 1797 fmt.Println(result) 1798 } 1799 1800 // To update the details of a policy 1801 // 1802 // The following example shows how to rename a policy and give it a new description 1803 // and new content. The output confirms the new name and description text:/n/n 1804 func ExampleOrganizations_UpdatePolicy_shared00() { 1805 svc := organizations.New(session.New()) 1806 input := &organizations.UpdatePolicyInput{ 1807 Description: aws.String("This description replaces the original."), 1808 Name: aws.String("Renamed-Policy"), 1809 PolicyId: aws.String("p-examplepolicyid111"), 1810 } 1811 1812 result, err := svc.UpdatePolicy(input) 1813 if err != nil { 1814 if aerr, ok := err.(awserr.Error); ok { 1815 switch aerr.Code() { 1816 case organizations.ErrCodeAccessDeniedException: 1817 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1818 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1819 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1820 case organizations.ErrCodeConcurrentModificationException: 1821 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 1822 case organizations.ErrCodeConstraintViolationException: 1823 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 1824 case organizations.ErrCodeDuplicatePolicyException: 1825 fmt.Println(organizations.ErrCodeDuplicatePolicyException, aerr.Error()) 1826 case organizations.ErrCodeInvalidInputException: 1827 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1828 case organizations.ErrCodeMalformedPolicyDocumentException: 1829 fmt.Println(organizations.ErrCodeMalformedPolicyDocumentException, aerr.Error()) 1830 case organizations.ErrCodePolicyNotFoundException: 1831 fmt.Println(organizations.ErrCodePolicyNotFoundException, aerr.Error()) 1832 case organizations.ErrCodeServiceException: 1833 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1834 case organizations.ErrCodeTooManyRequestsException: 1835 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1836 case organizations.ErrCodeUnsupportedAPIEndpointException: 1837 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 1838 case organizations.ErrCodePolicyChangesInProgressException: 1839 fmt.Println(organizations.ErrCodePolicyChangesInProgressException, aerr.Error()) 1840 default: 1841 fmt.Println(aerr.Error()) 1842 } 1843 } else { 1844 // Print the error, cast err to awserr.Error to get the Code and 1845 // Message from an error. 1846 fmt.Println(err.Error()) 1847 } 1848 return 1849 } 1850 1851 fmt.Println(result) 1852 } 1853 1854 // To update the content of a policy 1855 // 1856 // The following example shows how to replace the JSON text of the SCP from the preceding 1857 // example with a new JSON policy text string that allows S3 actions instead of EC2 1858 // actions:/n/n 1859 func ExampleOrganizations_UpdatePolicy_shared01() { 1860 svc := organizations.New(session.New()) 1861 input := &organizations.UpdatePolicyInput{ 1862 Content: aws.String("{ \\\"Version\\\": \\\"2012-10-17\\\", \\\"Statement\\\": {\\\"Effect\\\": \\\"Allow\\\", \\\"Action\\\": \\\"s3:*\\\", \\\"Resource\\\": \\\"*\\\" } }"), 1863 PolicyId: aws.String("p-examplepolicyid111"), 1864 } 1865 1866 result, err := svc.UpdatePolicy(input) 1867 if err != nil { 1868 if aerr, ok := err.(awserr.Error); ok { 1869 switch aerr.Code() { 1870 case organizations.ErrCodeAccessDeniedException: 1871 fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error()) 1872 case organizations.ErrCodeAWSOrganizationsNotInUseException: 1873 fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error()) 1874 case organizations.ErrCodeConcurrentModificationException: 1875 fmt.Println(organizations.ErrCodeConcurrentModificationException, aerr.Error()) 1876 case organizations.ErrCodeConstraintViolationException: 1877 fmt.Println(organizations.ErrCodeConstraintViolationException, aerr.Error()) 1878 case organizations.ErrCodeDuplicatePolicyException: 1879 fmt.Println(organizations.ErrCodeDuplicatePolicyException, aerr.Error()) 1880 case organizations.ErrCodeInvalidInputException: 1881 fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error()) 1882 case organizations.ErrCodeMalformedPolicyDocumentException: 1883 fmt.Println(organizations.ErrCodeMalformedPolicyDocumentException, aerr.Error()) 1884 case organizations.ErrCodePolicyNotFoundException: 1885 fmt.Println(organizations.ErrCodePolicyNotFoundException, aerr.Error()) 1886 case organizations.ErrCodeServiceException: 1887 fmt.Println(organizations.ErrCodeServiceException, aerr.Error()) 1888 case organizations.ErrCodeTooManyRequestsException: 1889 fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error()) 1890 case organizations.ErrCodeUnsupportedAPIEndpointException: 1891 fmt.Println(organizations.ErrCodeUnsupportedAPIEndpointException, aerr.Error()) 1892 case organizations.ErrCodePolicyChangesInProgressException: 1893 fmt.Println(organizations.ErrCodePolicyChangesInProgressException, aerr.Error()) 1894 default: 1895 fmt.Println(aerr.Error()) 1896 } 1897 } else { 1898 // Print the error, cast err to awserr.Error to get the Code and 1899 // Message from an error. 1900 fmt.Println(err.Error()) 1901 } 1902 return 1903 } 1904 1905 fmt.Println(result) 1906 }