github.com/aavshr/aws-sdk-go@v1.41.3/service/fsx/examples_test.go (about) 1 // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 3 package fsx_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/fsx" 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 copy a backup 29 // 30 // This operation copies an Amazon FSx backup. 31 func ExampleFSx_CopyBackup_shared00() { 32 svc := fsx.New(session.New()) 33 input := &fsx.CopyBackupInput{ 34 SourceBackupId: aws.String("backup-03e3c82e0183b7b6b"), 35 SourceRegion: aws.String("us-east-2"), 36 } 37 38 result, err := svc.CopyBackup(input) 39 if err != nil { 40 if aerr, ok := err.(awserr.Error); ok { 41 switch aerr.Code() { 42 case fsx.ErrCodeBadRequest: 43 fmt.Println(fsx.ErrCodeBadRequest, aerr.Error()) 44 case fsx.ErrCodeBackupNotFound: 45 fmt.Println(fsx.ErrCodeBackupNotFound, aerr.Error()) 46 case fsx.ErrCodeServiceLimitExceeded: 47 fmt.Println(fsx.ErrCodeServiceLimitExceeded, aerr.Error()) 48 case fsx.ErrCodeUnsupportedOperation: 49 fmt.Println(fsx.ErrCodeUnsupportedOperation, aerr.Error()) 50 case fsx.ErrCodeIncompatibleParameterError: 51 fmt.Println(fsx.ErrCodeIncompatibleParameterError, aerr.Error()) 52 case fsx.ErrCodeInternalServerError: 53 fmt.Println(fsx.ErrCodeInternalServerError, aerr.Error()) 54 case fsx.ErrCodeInvalidSourceKmsKey: 55 fmt.Println(fsx.ErrCodeInvalidSourceKmsKey, aerr.Error()) 56 case fsx.ErrCodeInvalidDestinationKmsKey: 57 fmt.Println(fsx.ErrCodeInvalidDestinationKmsKey, aerr.Error()) 58 case fsx.ErrCodeInvalidRegion: 59 fmt.Println(fsx.ErrCodeInvalidRegion, aerr.Error()) 60 case fsx.ErrCodeSourceBackupUnavailable: 61 fmt.Println(fsx.ErrCodeSourceBackupUnavailable, aerr.Error()) 62 case fsx.ErrCodeIncompatibleRegionForMultiAZ: 63 fmt.Println(fsx.ErrCodeIncompatibleRegionForMultiAZ, aerr.Error()) 64 default: 65 fmt.Println(aerr.Error()) 66 } 67 } else { 68 // Print the error, cast err to awserr.Error to get the Code and 69 // Message from an error. 70 fmt.Println(err.Error()) 71 } 72 return 73 } 74 75 fmt.Println(result) 76 } 77 78 // To create a new backup 79 // 80 // This operation creates a new backup. 81 func ExampleFSx_CreateBackup_shared00() { 82 svc := fsx.New(session.New()) 83 input := &fsx.CreateBackupInput{ 84 FileSystemId: aws.String("fs-0498eed5fe91001ec"), 85 Tags: []*fsx.Tag{ 86 { 87 Key: aws.String("Name"), 88 Value: aws.String("MyBackup"), 89 }, 90 }, 91 } 92 93 result, err := svc.CreateBackup(input) 94 if err != nil { 95 if aerr, ok := err.(awserr.Error); ok { 96 switch aerr.Code() { 97 case fsx.ErrCodeBadRequest: 98 fmt.Println(fsx.ErrCodeBadRequest, aerr.Error()) 99 case fsx.ErrCodeUnsupportedOperation: 100 fmt.Println(fsx.ErrCodeUnsupportedOperation, aerr.Error()) 101 case fsx.ErrCodeFileSystemNotFound: 102 fmt.Println(fsx.ErrCodeFileSystemNotFound, aerr.Error()) 103 case fsx.ErrCodeVolumeNotFound: 104 fmt.Println(fsx.ErrCodeVolumeNotFound, aerr.Error()) 105 case fsx.ErrCodeBackupInProgress: 106 fmt.Println(fsx.ErrCodeBackupInProgress, aerr.Error()) 107 case fsx.ErrCodeIncompatibleParameterError: 108 fmt.Println(fsx.ErrCodeIncompatibleParameterError, aerr.Error()) 109 case fsx.ErrCodeServiceLimitExceeded: 110 fmt.Println(fsx.ErrCodeServiceLimitExceeded, aerr.Error()) 111 case fsx.ErrCodeInternalServerError: 112 fmt.Println(fsx.ErrCodeInternalServerError, aerr.Error()) 113 default: 114 fmt.Println(aerr.Error()) 115 } 116 } else { 117 // Print the error, cast err to awserr.Error to get the Code and 118 // Message from an error. 119 fmt.Println(err.Error()) 120 } 121 return 122 } 123 124 fmt.Println(result) 125 } 126 127 // To create a new file system 128 // 129 // This operation creates a new Amazon FSx for Windows File Server file system. 130 func ExampleFSx_CreateFileSystem_shared00() { 131 svc := fsx.New(session.New()) 132 input := &fsx.CreateFileSystemInput{ 133 ClientRequestToken: aws.String("a8ca07e4-61ec-4399-99f4-19853801bcd5"), 134 FileSystemType: aws.String("WINDOWS"), 135 KmsKeyId: aws.String("arn:aws:kms:us-east-1:012345678912:key/1111abcd-2222-3333-4444-55556666eeff"), 136 SecurityGroupIds: []*string{ 137 aws.String("sg-edcd9784"), 138 }, 139 StorageCapacity: aws.Int64(3200), 140 StorageType: aws.String("HDD"), 141 SubnetIds: []*string{ 142 aws.String("subnet-1234abcd"), 143 }, 144 Tags: []*fsx.Tag{ 145 { 146 Key: aws.String("Name"), 147 Value: aws.String("MyFileSystem"), 148 }, 149 }, 150 WindowsConfiguration: &fsx.CreateFileSystemWindowsConfiguration{ 151 ActiveDirectoryId: aws.String("d-1234abcd12"), 152 Aliases: []*string{ 153 aws.String("accounting.corp.example.com"), 154 }, 155 AutomaticBackupRetentionDays: aws.Int64(30), 156 DailyAutomaticBackupStartTime: aws.String("05:00"), 157 ThroughputCapacity: aws.Int64(32), 158 WeeklyMaintenanceStartTime: aws.String("1:05:00"), 159 }, 160 } 161 162 result, err := svc.CreateFileSystem(input) 163 if err != nil { 164 if aerr, ok := err.(awserr.Error); ok { 165 switch aerr.Code() { 166 case fsx.ErrCodeBadRequest: 167 fmt.Println(fsx.ErrCodeBadRequest, aerr.Error()) 168 case fsx.ErrCodeActiveDirectoryError: 169 fmt.Println(fsx.ErrCodeActiveDirectoryError, aerr.Error()) 170 case fsx.ErrCodeIncompatibleParameterError: 171 fmt.Println(fsx.ErrCodeIncompatibleParameterError, aerr.Error()) 172 case fsx.ErrCodeInvalidImportPath: 173 fmt.Println(fsx.ErrCodeInvalidImportPath, aerr.Error()) 174 case fsx.ErrCodeInvalidExportPath: 175 fmt.Println(fsx.ErrCodeInvalidExportPath, aerr.Error()) 176 case fsx.ErrCodeInvalidNetworkSettings: 177 fmt.Println(fsx.ErrCodeInvalidNetworkSettings, aerr.Error()) 178 case fsx.ErrCodeInvalidPerUnitStorageThroughput: 179 fmt.Println(fsx.ErrCodeInvalidPerUnitStorageThroughput, aerr.Error()) 180 case fsx.ErrCodeServiceLimitExceeded: 181 fmt.Println(fsx.ErrCodeServiceLimitExceeded, aerr.Error()) 182 case fsx.ErrCodeInternalServerError: 183 fmt.Println(fsx.ErrCodeInternalServerError, aerr.Error()) 184 case fsx.ErrCodeMissingFileSystemConfiguration: 185 fmt.Println(fsx.ErrCodeMissingFileSystemConfiguration, aerr.Error()) 186 default: 187 fmt.Println(aerr.Error()) 188 } 189 } else { 190 // Print the error, cast err to awserr.Error to get the Code and 191 // Message from an error. 192 fmt.Println(err.Error()) 193 } 194 return 195 } 196 197 fmt.Println(result) 198 } 199 200 // To create a new file system from backup 201 // 202 // This operation creates a new file system from backup. 203 func ExampleFSx_CreateFileSystemFromBackup_shared00() { 204 svc := fsx.New(session.New()) 205 input := &fsx.CreateFileSystemFromBackupInput{ 206 BackupId: aws.String("backup-03e3c82e0183b7b6b"), 207 ClientRequestToken: aws.String("f4c94ed7-238d-4c46-93db-48cd62ec33b7"), 208 SecurityGroupIds: []*string{ 209 aws.String("sg-edcd9784"), 210 }, 211 SubnetIds: []*string{ 212 aws.String("subnet-1234abcd"), 213 }, 214 Tags: []*fsx.Tag{ 215 { 216 Key: aws.String("Name"), 217 Value: aws.String("MyFileSystem"), 218 }, 219 }, 220 WindowsConfiguration: &fsx.CreateFileSystemWindowsConfiguration{ 221 ThroughputCapacity: aws.Int64(8), 222 }, 223 } 224 225 result, err := svc.CreateFileSystemFromBackup(input) 226 if err != nil { 227 if aerr, ok := err.(awserr.Error); ok { 228 switch aerr.Code() { 229 case fsx.ErrCodeBadRequest: 230 fmt.Println(fsx.ErrCodeBadRequest, aerr.Error()) 231 case fsx.ErrCodeActiveDirectoryError: 232 fmt.Println(fsx.ErrCodeActiveDirectoryError, aerr.Error()) 233 case fsx.ErrCodeIncompatibleParameterError: 234 fmt.Println(fsx.ErrCodeIncompatibleParameterError, aerr.Error()) 235 case fsx.ErrCodeInvalidNetworkSettings: 236 fmt.Println(fsx.ErrCodeInvalidNetworkSettings, aerr.Error()) 237 case fsx.ErrCodeInvalidPerUnitStorageThroughput: 238 fmt.Println(fsx.ErrCodeInvalidPerUnitStorageThroughput, aerr.Error()) 239 case fsx.ErrCodeServiceLimitExceeded: 240 fmt.Println(fsx.ErrCodeServiceLimitExceeded, aerr.Error()) 241 case fsx.ErrCodeBackupNotFound: 242 fmt.Println(fsx.ErrCodeBackupNotFound, aerr.Error()) 243 case fsx.ErrCodeInternalServerError: 244 fmt.Println(fsx.ErrCodeInternalServerError, aerr.Error()) 245 case fsx.ErrCodeMissingFileSystemConfiguration: 246 fmt.Println(fsx.ErrCodeMissingFileSystemConfiguration, 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 delete a backup 262 // 263 // This operation deletes an Amazon FSx file system backup. 264 func ExampleFSx_DeleteBackup_shared00() { 265 svc := fsx.New(session.New()) 266 input := &fsx.DeleteBackupInput{ 267 BackupId: aws.String("backup-03e3c82e0183b7b6b"), 268 } 269 270 result, err := svc.DeleteBackup(input) 271 if err != nil { 272 if aerr, ok := err.(awserr.Error); ok { 273 switch aerr.Code() { 274 case fsx.ErrCodeBadRequest: 275 fmt.Println(fsx.ErrCodeBadRequest, aerr.Error()) 276 case fsx.ErrCodeBackupInProgress: 277 fmt.Println(fsx.ErrCodeBackupInProgress, aerr.Error()) 278 case fsx.ErrCodeBackupNotFound: 279 fmt.Println(fsx.ErrCodeBackupNotFound, aerr.Error()) 280 case fsx.ErrCodeBackupRestoring: 281 fmt.Println(fsx.ErrCodeBackupRestoring, aerr.Error()) 282 case fsx.ErrCodeIncompatibleParameterError: 283 fmt.Println(fsx.ErrCodeIncompatibleParameterError, aerr.Error()) 284 case fsx.ErrCodeInternalServerError: 285 fmt.Println(fsx.ErrCodeInternalServerError, aerr.Error()) 286 case fsx.ErrCodeBackupBeingCopied: 287 fmt.Println(fsx.ErrCodeBackupBeingCopied, aerr.Error()) 288 default: 289 fmt.Println(aerr.Error()) 290 } 291 } else { 292 // Print the error, cast err to awserr.Error to get the Code and 293 // Message from an error. 294 fmt.Println(err.Error()) 295 } 296 return 297 } 298 299 fmt.Println(result) 300 } 301 302 // To delete a file system 303 // 304 // This operation deletes an Amazon FSx file system. 305 func ExampleFSx_DeleteFileSystem_shared00() { 306 svc := fsx.New(session.New()) 307 input := &fsx.DeleteFileSystemInput{ 308 FileSystemId: aws.String("fs-0498eed5fe91001ec"), 309 } 310 311 result, err := svc.DeleteFileSystem(input) 312 if err != nil { 313 if aerr, ok := err.(awserr.Error); ok { 314 switch aerr.Code() { 315 case fsx.ErrCodeBadRequest: 316 fmt.Println(fsx.ErrCodeBadRequest, aerr.Error()) 317 case fsx.ErrCodeIncompatibleParameterError: 318 fmt.Println(fsx.ErrCodeIncompatibleParameterError, aerr.Error()) 319 case fsx.ErrCodeFileSystemNotFound: 320 fmt.Println(fsx.ErrCodeFileSystemNotFound, aerr.Error()) 321 case fsx.ErrCodeServiceLimitExceeded: 322 fmt.Println(fsx.ErrCodeServiceLimitExceeded, aerr.Error()) 323 case fsx.ErrCodeInternalServerError: 324 fmt.Println(fsx.ErrCodeInternalServerError, aerr.Error()) 325 default: 326 fmt.Println(aerr.Error()) 327 } 328 } else { 329 // Print the error, cast err to awserr.Error to get the Code and 330 // Message from an error. 331 fmt.Println(err.Error()) 332 } 333 return 334 } 335 336 fmt.Println(result) 337 } 338 339 // To describe Amazon FSx backups 340 // 341 // This operation describes all of the Amazon FSx backups in an account. 342 func ExampleFSx_DescribeBackups_shared00() { 343 svc := fsx.New(session.New()) 344 input := &fsx.DescribeBackupsInput{} 345 346 result, err := svc.DescribeBackups(input) 347 if err != nil { 348 if aerr, ok := err.(awserr.Error); ok { 349 switch aerr.Code() { 350 case fsx.ErrCodeBadRequest: 351 fmt.Println(fsx.ErrCodeBadRequest, aerr.Error()) 352 case fsx.ErrCodeFileSystemNotFound: 353 fmt.Println(fsx.ErrCodeFileSystemNotFound, aerr.Error()) 354 case fsx.ErrCodeVolumeNotFound: 355 fmt.Println(fsx.ErrCodeVolumeNotFound, aerr.Error()) 356 case fsx.ErrCodeBackupNotFound: 357 fmt.Println(fsx.ErrCodeBackupNotFound, aerr.Error()) 358 case fsx.ErrCodeInternalServerError: 359 fmt.Println(fsx.ErrCodeInternalServerError, aerr.Error()) 360 default: 361 fmt.Println(aerr.Error()) 362 } 363 } else { 364 // Print the error, cast err to awserr.Error to get the Code and 365 // Message from an error. 366 fmt.Println(err.Error()) 367 } 368 return 369 } 370 371 fmt.Println(result) 372 } 373 374 // To describe an Amazon FSx file system 375 // 376 // This operation describes all of the Amazon FSx file systems in an account. 377 func ExampleFSx_DescribeFileSystems_shared00() { 378 svc := fsx.New(session.New()) 379 input := &fsx.DescribeFileSystemsInput{} 380 381 result, err := svc.DescribeFileSystems(input) 382 if err != nil { 383 if aerr, ok := err.(awserr.Error); ok { 384 switch aerr.Code() { 385 case fsx.ErrCodeBadRequest: 386 fmt.Println(fsx.ErrCodeBadRequest, aerr.Error()) 387 case fsx.ErrCodeFileSystemNotFound: 388 fmt.Println(fsx.ErrCodeFileSystemNotFound, aerr.Error()) 389 case fsx.ErrCodeInternalServerError: 390 fmt.Println(fsx.ErrCodeInternalServerError, aerr.Error()) 391 default: 392 fmt.Println(aerr.Error()) 393 } 394 } else { 395 // Print the error, cast err to awserr.Error to get the Code and 396 // Message from an error. 397 fmt.Println(err.Error()) 398 } 399 return 400 } 401 402 fmt.Println(result) 403 } 404 405 // To list tags for a resource 406 // 407 // This operation lists tags for an Amazon FSx resource. 408 func ExampleFSx_ListTagsForResource_shared00() { 409 svc := fsx.New(session.New()) 410 input := &fsx.ListTagsForResourceInput{ 411 ResourceARN: aws.String("arn:aws:fsx:us-east-1:012345678912:file-system/fs-0498eed5fe91001ec"), 412 } 413 414 result, err := svc.ListTagsForResource(input) 415 if err != nil { 416 if aerr, ok := err.(awserr.Error); ok { 417 switch aerr.Code() { 418 case fsx.ErrCodeBadRequest: 419 fmt.Println(fsx.ErrCodeBadRequest, aerr.Error()) 420 case fsx.ErrCodeInternalServerError: 421 fmt.Println(fsx.ErrCodeInternalServerError, aerr.Error()) 422 case fsx.ErrCodeResourceNotFound: 423 fmt.Println(fsx.ErrCodeResourceNotFound, aerr.Error()) 424 case fsx.ErrCodeNotServiceResourceError: 425 fmt.Println(fsx.ErrCodeNotServiceResourceError, aerr.Error()) 426 case fsx.ErrCodeResourceDoesNotSupportTagging: 427 fmt.Println(fsx.ErrCodeResourceDoesNotSupportTagging, aerr.Error()) 428 default: 429 fmt.Println(aerr.Error()) 430 } 431 } else { 432 // Print the error, cast err to awserr.Error to get the Code and 433 // Message from an error. 434 fmt.Println(err.Error()) 435 } 436 return 437 } 438 439 fmt.Println(result) 440 } 441 442 // To tag a resource 443 // 444 // This operation tags an Amazon FSx resource. 445 func ExampleFSx_TagResource_shared00() { 446 svc := fsx.New(session.New()) 447 input := &fsx.TagResourceInput{ 448 ResourceARN: aws.String("arn:aws:fsx:us-east-1:012345678912:file-system/fs-0498eed5fe91001ec"), 449 Tags: []*fsx.Tag{ 450 { 451 Key: aws.String("Name"), 452 Value: aws.String("MyFileSystem"), 453 }, 454 }, 455 } 456 457 result, err := svc.TagResource(input) 458 if err != nil { 459 if aerr, ok := err.(awserr.Error); ok { 460 switch aerr.Code() { 461 case fsx.ErrCodeBadRequest: 462 fmt.Println(fsx.ErrCodeBadRequest, aerr.Error()) 463 case fsx.ErrCodeInternalServerError: 464 fmt.Println(fsx.ErrCodeInternalServerError, aerr.Error()) 465 case fsx.ErrCodeResourceNotFound: 466 fmt.Println(fsx.ErrCodeResourceNotFound, aerr.Error()) 467 case fsx.ErrCodeNotServiceResourceError: 468 fmt.Println(fsx.ErrCodeNotServiceResourceError, aerr.Error()) 469 case fsx.ErrCodeResourceDoesNotSupportTagging: 470 fmt.Println(fsx.ErrCodeResourceDoesNotSupportTagging, aerr.Error()) 471 default: 472 fmt.Println(aerr.Error()) 473 } 474 } else { 475 // Print the error, cast err to awserr.Error to get the Code and 476 // Message from an error. 477 fmt.Println(err.Error()) 478 } 479 return 480 } 481 482 fmt.Println(result) 483 } 484 485 // To untag a resource 486 // 487 // This operation untags an Amazon FSx resource. 488 func ExampleFSx_UntagResource_shared00() { 489 svc := fsx.New(session.New()) 490 input := &fsx.UntagResourceInput{ 491 ResourceARN: aws.String("arn:aws:fsx:us-east-1:012345678912:file-system/fs-0498eed5fe91001ec"), 492 TagKeys: []*string{ 493 aws.String("Name"), 494 }, 495 } 496 497 result, err := svc.UntagResource(input) 498 if err != nil { 499 if aerr, ok := err.(awserr.Error); ok { 500 switch aerr.Code() { 501 case fsx.ErrCodeBadRequest: 502 fmt.Println(fsx.ErrCodeBadRequest, aerr.Error()) 503 case fsx.ErrCodeInternalServerError: 504 fmt.Println(fsx.ErrCodeInternalServerError, aerr.Error()) 505 case fsx.ErrCodeResourceNotFound: 506 fmt.Println(fsx.ErrCodeResourceNotFound, aerr.Error()) 507 case fsx.ErrCodeNotServiceResourceError: 508 fmt.Println(fsx.ErrCodeNotServiceResourceError, aerr.Error()) 509 case fsx.ErrCodeResourceDoesNotSupportTagging: 510 fmt.Println(fsx.ErrCodeResourceDoesNotSupportTagging, aerr.Error()) 511 default: 512 fmt.Println(aerr.Error()) 513 } 514 } else { 515 // Print the error, cast err to awserr.Error to get the Code and 516 // Message from an error. 517 fmt.Println(err.Error()) 518 } 519 return 520 } 521 522 fmt.Println(result) 523 } 524 525 // To update an existing file system 526 // 527 // This operation updates an existing file system. 528 func ExampleFSx_UpdateFileSystem_shared00() { 529 svc := fsx.New(session.New()) 530 input := &fsx.UpdateFileSystemInput{ 531 FileSystemId: aws.String("fs-0498eed5fe91001ec"), 532 WindowsConfiguration: &fsx.UpdateFileSystemWindowsConfiguration{ 533 AutomaticBackupRetentionDays: aws.Int64(10), 534 DailyAutomaticBackupStartTime: aws.String("06:00"), 535 WeeklyMaintenanceStartTime: aws.String("3:06:00"), 536 }, 537 } 538 539 result, err := svc.UpdateFileSystem(input) 540 if err != nil { 541 if aerr, ok := err.(awserr.Error); ok { 542 switch aerr.Code() { 543 case fsx.ErrCodeBadRequest: 544 fmt.Println(fsx.ErrCodeBadRequest, aerr.Error()) 545 case fsx.ErrCodeUnsupportedOperation: 546 fmt.Println(fsx.ErrCodeUnsupportedOperation, aerr.Error()) 547 case fsx.ErrCodeIncompatibleParameterError: 548 fmt.Println(fsx.ErrCodeIncompatibleParameterError, aerr.Error()) 549 case fsx.ErrCodeInternalServerError: 550 fmt.Println(fsx.ErrCodeInternalServerError, aerr.Error()) 551 case fsx.ErrCodeFileSystemNotFound: 552 fmt.Println(fsx.ErrCodeFileSystemNotFound, aerr.Error()) 553 case fsx.ErrCodeMissingFileSystemConfiguration: 554 fmt.Println(fsx.ErrCodeMissingFileSystemConfiguration, aerr.Error()) 555 case fsx.ErrCodeServiceLimitExceeded: 556 fmt.Println(fsx.ErrCodeServiceLimitExceeded, aerr.Error()) 557 default: 558 fmt.Println(aerr.Error()) 559 } 560 } else { 561 // Print the error, cast err to awserr.Error to get the Code and 562 // Message from an error. 563 fmt.Println(err.Error()) 564 } 565 return 566 } 567 568 fmt.Println(result) 569 }