github.com/aavshr/aws-sdk-go@v1.41.3/service/dynamodb/examples_test.go (about) 1 // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 3 package dynamodb_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/dynamodb" 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 retrieve multiple items from a table 29 // 30 // This example reads multiple items from the Music table using a batch of three GetItem 31 // requests. Only the AlbumTitle attribute is returned. 32 func ExampleDynamoDB_BatchGetItem_shared00() { 33 svc := dynamodb.New(session.New()) 34 input := &dynamodb.BatchGetItemInput{ 35 RequestItems: map[string]*dynamodb.KeysAndAttributes{ 36 "Music": { 37 Keys: []map[string]*dynamodb.AttributeValue{ 38 { 39 "Artist": &dynamodb.AttributeValue{ 40 S: aws.String("No One You Know"), 41 }, 42 "SongTitle": &dynamodb.AttributeValue{ 43 S: aws.String("Call Me Today"), 44 }, 45 }, 46 { 47 "Artist": &dynamodb.AttributeValue{ 48 S: aws.String("Acme Band"), 49 }, 50 "SongTitle": &dynamodb.AttributeValue{ 51 S: aws.String("Happy Day"), 52 }, 53 }, 54 { 55 "Artist": &dynamodb.AttributeValue{ 56 S: aws.String("No One You Know"), 57 }, 58 "SongTitle": &dynamodb.AttributeValue{ 59 S: aws.String("Scared of My Shadow"), 60 }, 61 }, 62 }, 63 ProjectionExpression: aws.String("AlbumTitle"), 64 }, 65 }, 66 } 67 68 result, err := svc.BatchGetItem(input) 69 if err != nil { 70 if aerr, ok := err.(awserr.Error); ok { 71 switch aerr.Code() { 72 case dynamodb.ErrCodeProvisionedThroughputExceededException: 73 fmt.Println(dynamodb.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 74 case dynamodb.ErrCodeResourceNotFoundException: 75 fmt.Println(dynamodb.ErrCodeResourceNotFoundException, aerr.Error()) 76 case dynamodb.ErrCodeRequestLimitExceeded: 77 fmt.Println(dynamodb.ErrCodeRequestLimitExceeded, aerr.Error()) 78 case dynamodb.ErrCodeInternalServerError: 79 fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) 80 default: 81 fmt.Println(aerr.Error()) 82 } 83 } else { 84 // Print the error, cast err to awserr.Error to get the Code and 85 // Message from an error. 86 fmt.Println(err.Error()) 87 } 88 return 89 } 90 91 fmt.Println(result) 92 } 93 94 // To add multiple items to a table 95 // 96 // This example adds three new items to the Music table using a batch of three PutItem 97 // requests. 98 func ExampleDynamoDB_BatchWriteItem_shared00() { 99 svc := dynamodb.New(session.New()) 100 input := &dynamodb.BatchWriteItemInput{ 101 RequestItems: map[string][]*dynamodb.WriteRequest{ 102 "Music": { 103 { 104 PutRequest: &dynamodb.PutRequest{ 105 Item: map[string]*dynamodb.AttributeValue{ 106 "AlbumTitle": { 107 S: aws.String("Somewhat Famous"), 108 }, 109 "Artist": { 110 S: aws.String("No One You Know"), 111 }, 112 "SongTitle": { 113 S: aws.String("Call Me Today"), 114 }, 115 }, 116 }, 117 }, 118 { 119 PutRequest: &dynamodb.PutRequest{ 120 Item: map[string]*dynamodb.AttributeValue{ 121 "AlbumTitle": { 122 S: aws.String("Songs About Life"), 123 }, 124 "Artist": { 125 S: aws.String("Acme Band"), 126 }, 127 "SongTitle": { 128 S: aws.String("Happy Day"), 129 }, 130 }, 131 }, 132 }, 133 { 134 PutRequest: &dynamodb.PutRequest{ 135 Item: map[string]*dynamodb.AttributeValue{ 136 "AlbumTitle": { 137 S: aws.String("Blue Sky Blues"), 138 }, 139 "Artist": { 140 S: aws.String("No One You Know"), 141 }, 142 "SongTitle": { 143 S: aws.String("Scared of My Shadow"), 144 }, 145 }, 146 }, 147 }, 148 }, 149 }, 150 } 151 152 result, err := svc.BatchWriteItem(input) 153 if err != nil { 154 if aerr, ok := err.(awserr.Error); ok { 155 switch aerr.Code() { 156 case dynamodb.ErrCodeProvisionedThroughputExceededException: 157 fmt.Println(dynamodb.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 158 case dynamodb.ErrCodeResourceNotFoundException: 159 fmt.Println(dynamodb.ErrCodeResourceNotFoundException, aerr.Error()) 160 case dynamodb.ErrCodeItemCollectionSizeLimitExceededException: 161 fmt.Println(dynamodb.ErrCodeItemCollectionSizeLimitExceededException, aerr.Error()) 162 case dynamodb.ErrCodeRequestLimitExceeded: 163 fmt.Println(dynamodb.ErrCodeRequestLimitExceeded, aerr.Error()) 164 case dynamodb.ErrCodeInternalServerError: 165 fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) 166 default: 167 fmt.Println(aerr.Error()) 168 } 169 } else { 170 // Print the error, cast err to awserr.Error to get the Code and 171 // Message from an error. 172 fmt.Println(err.Error()) 173 } 174 return 175 } 176 177 fmt.Println(result) 178 } 179 180 // To create a table 181 // 182 // This example creates a table named Music. 183 func ExampleDynamoDB_CreateTable_shared00() { 184 svc := dynamodb.New(session.New()) 185 input := &dynamodb.CreateTableInput{ 186 AttributeDefinitions: []*dynamodb.AttributeDefinition{ 187 { 188 AttributeName: aws.String("Artist"), 189 AttributeType: aws.String("S"), 190 }, 191 { 192 AttributeName: aws.String("SongTitle"), 193 AttributeType: aws.String("S"), 194 }, 195 }, 196 KeySchema: []*dynamodb.KeySchemaElement{ 197 { 198 AttributeName: aws.String("Artist"), 199 KeyType: aws.String("HASH"), 200 }, 201 { 202 AttributeName: aws.String("SongTitle"), 203 KeyType: aws.String("RANGE"), 204 }, 205 }, 206 ProvisionedThroughput: &dynamodb.ProvisionedThroughput{ 207 ReadCapacityUnits: aws.Int64(5), 208 WriteCapacityUnits: aws.Int64(5), 209 }, 210 TableName: aws.String("Music"), 211 } 212 213 result, err := svc.CreateTable(input) 214 if err != nil { 215 if aerr, ok := err.(awserr.Error); ok { 216 switch aerr.Code() { 217 case dynamodb.ErrCodeResourceInUseException: 218 fmt.Println(dynamodb.ErrCodeResourceInUseException, aerr.Error()) 219 case dynamodb.ErrCodeLimitExceededException: 220 fmt.Println(dynamodb.ErrCodeLimitExceededException, aerr.Error()) 221 case dynamodb.ErrCodeInternalServerError: 222 fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) 223 default: 224 fmt.Println(aerr.Error()) 225 } 226 } else { 227 // Print the error, cast err to awserr.Error to get the Code and 228 // Message from an error. 229 fmt.Println(err.Error()) 230 } 231 return 232 } 233 234 fmt.Println(result) 235 } 236 237 // To delete an item 238 // 239 // This example deletes an item from the Music table. 240 func ExampleDynamoDB_DeleteItem_shared00() { 241 svc := dynamodb.New(session.New()) 242 input := &dynamodb.DeleteItemInput{ 243 Key: map[string]*dynamodb.AttributeValue{ 244 "Artist": { 245 S: aws.String("No One You Know"), 246 }, 247 "SongTitle": { 248 S: aws.String("Scared of My Shadow"), 249 }, 250 }, 251 TableName: aws.String("Music"), 252 } 253 254 result, err := svc.DeleteItem(input) 255 if err != nil { 256 if aerr, ok := err.(awserr.Error); ok { 257 switch aerr.Code() { 258 case dynamodb.ErrCodeConditionalCheckFailedException: 259 fmt.Println(dynamodb.ErrCodeConditionalCheckFailedException, aerr.Error()) 260 case dynamodb.ErrCodeProvisionedThroughputExceededException: 261 fmt.Println(dynamodb.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 262 case dynamodb.ErrCodeResourceNotFoundException: 263 fmt.Println(dynamodb.ErrCodeResourceNotFoundException, aerr.Error()) 264 case dynamodb.ErrCodeItemCollectionSizeLimitExceededException: 265 fmt.Println(dynamodb.ErrCodeItemCollectionSizeLimitExceededException, aerr.Error()) 266 case dynamodb.ErrCodeTransactionConflictException: 267 fmt.Println(dynamodb.ErrCodeTransactionConflictException, aerr.Error()) 268 case dynamodb.ErrCodeRequestLimitExceeded: 269 fmt.Println(dynamodb.ErrCodeRequestLimitExceeded, aerr.Error()) 270 case dynamodb.ErrCodeInternalServerError: 271 fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) 272 default: 273 fmt.Println(aerr.Error()) 274 } 275 } else { 276 // Print the error, cast err to awserr.Error to get the Code and 277 // Message from an error. 278 fmt.Println(err.Error()) 279 } 280 return 281 } 282 283 fmt.Println(result) 284 } 285 286 // To delete a table 287 // 288 // This example deletes the Music table. 289 func ExampleDynamoDB_DeleteTable_shared00() { 290 svc := dynamodb.New(session.New()) 291 input := &dynamodb.DeleteTableInput{ 292 TableName: aws.String("Music"), 293 } 294 295 result, err := svc.DeleteTable(input) 296 if err != nil { 297 if aerr, ok := err.(awserr.Error); ok { 298 switch aerr.Code() { 299 case dynamodb.ErrCodeResourceInUseException: 300 fmt.Println(dynamodb.ErrCodeResourceInUseException, aerr.Error()) 301 case dynamodb.ErrCodeResourceNotFoundException: 302 fmt.Println(dynamodb.ErrCodeResourceNotFoundException, aerr.Error()) 303 case dynamodb.ErrCodeLimitExceededException: 304 fmt.Println(dynamodb.ErrCodeLimitExceededException, aerr.Error()) 305 case dynamodb.ErrCodeInternalServerError: 306 fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) 307 default: 308 fmt.Println(aerr.Error()) 309 } 310 } else { 311 // Print the error, cast err to awserr.Error to get the Code and 312 // Message from an error. 313 fmt.Println(err.Error()) 314 } 315 return 316 } 317 318 fmt.Println(result) 319 } 320 321 // To determine capacity limits per table and account, in the current AWS region 322 // 323 // The following example returns the maximum read and write capacity units per table, 324 // and for the AWS account, in the current AWS region. 325 func ExampleDynamoDB_DescribeLimits_shared00() { 326 svc := dynamodb.New(session.New()) 327 input := &dynamodb.DescribeLimitsInput{} 328 329 result, err := svc.DescribeLimits(input) 330 if err != nil { 331 if aerr, ok := err.(awserr.Error); ok { 332 switch aerr.Code() { 333 case dynamodb.ErrCodeInternalServerError: 334 fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) 335 default: 336 fmt.Println(aerr.Error()) 337 } 338 } else { 339 // Print the error, cast err to awserr.Error to get the Code and 340 // Message from an error. 341 fmt.Println(err.Error()) 342 } 343 return 344 } 345 346 fmt.Println(result) 347 } 348 349 // To describe a table 350 // 351 // This example describes the Music table. 352 func ExampleDynamoDB_DescribeTable_shared00() { 353 svc := dynamodb.New(session.New()) 354 input := &dynamodb.DescribeTableInput{ 355 TableName: aws.String("Music"), 356 } 357 358 result, err := svc.DescribeTable(input) 359 if err != nil { 360 if aerr, ok := err.(awserr.Error); ok { 361 switch aerr.Code() { 362 case dynamodb.ErrCodeResourceNotFoundException: 363 fmt.Println(dynamodb.ErrCodeResourceNotFoundException, aerr.Error()) 364 case dynamodb.ErrCodeInternalServerError: 365 fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) 366 default: 367 fmt.Println(aerr.Error()) 368 } 369 } else { 370 // Print the error, cast err to awserr.Error to get the Code and 371 // Message from an error. 372 fmt.Println(err.Error()) 373 } 374 return 375 } 376 377 fmt.Println(result) 378 } 379 380 // To read an item from a table 381 // 382 // This example retrieves an item from the Music table. The table has a partition key 383 // and a sort key (Artist and SongTitle), so you must specify both of these attributes. 384 func ExampleDynamoDB_GetItem_shared00() { 385 svc := dynamodb.New(session.New()) 386 input := &dynamodb.GetItemInput{ 387 Key: map[string]*dynamodb.AttributeValue{ 388 "Artist": { 389 S: aws.String("Acme Band"), 390 }, 391 "SongTitle": { 392 S: aws.String("Happy Day"), 393 }, 394 }, 395 TableName: aws.String("Music"), 396 } 397 398 result, err := svc.GetItem(input) 399 if err != nil { 400 if aerr, ok := err.(awserr.Error); ok { 401 switch aerr.Code() { 402 case dynamodb.ErrCodeProvisionedThroughputExceededException: 403 fmt.Println(dynamodb.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 404 case dynamodb.ErrCodeResourceNotFoundException: 405 fmt.Println(dynamodb.ErrCodeResourceNotFoundException, aerr.Error()) 406 case dynamodb.ErrCodeRequestLimitExceeded: 407 fmt.Println(dynamodb.ErrCodeRequestLimitExceeded, aerr.Error()) 408 case dynamodb.ErrCodeInternalServerError: 409 fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) 410 default: 411 fmt.Println(aerr.Error()) 412 } 413 } else { 414 // Print the error, cast err to awserr.Error to get the Code and 415 // Message from an error. 416 fmt.Println(err.Error()) 417 } 418 return 419 } 420 421 fmt.Println(result) 422 } 423 424 // To list tables 425 // 426 // This example lists all of the tables associated with the current AWS account and 427 // endpoint. 428 func ExampleDynamoDB_ListTables_shared00() { 429 svc := dynamodb.New(session.New()) 430 input := &dynamodb.ListTablesInput{} 431 432 result, err := svc.ListTables(input) 433 if err != nil { 434 if aerr, ok := err.(awserr.Error); ok { 435 switch aerr.Code() { 436 case dynamodb.ErrCodeInternalServerError: 437 fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) 438 default: 439 fmt.Println(aerr.Error()) 440 } 441 } else { 442 // Print the error, cast err to awserr.Error to get the Code and 443 // Message from an error. 444 fmt.Println(err.Error()) 445 } 446 return 447 } 448 449 fmt.Println(result) 450 } 451 452 // To add an item to a table 453 // 454 // This example adds a new item to the Music table. 455 func ExampleDynamoDB_PutItem_shared00() { 456 svc := dynamodb.New(session.New()) 457 input := &dynamodb.PutItemInput{ 458 Item: map[string]*dynamodb.AttributeValue{ 459 "AlbumTitle": { 460 S: aws.String("Somewhat Famous"), 461 }, 462 "Artist": { 463 S: aws.String("No One You Know"), 464 }, 465 "SongTitle": { 466 S: aws.String("Call Me Today"), 467 }, 468 }, 469 ReturnConsumedCapacity: aws.String("TOTAL"), 470 TableName: aws.String("Music"), 471 } 472 473 result, err := svc.PutItem(input) 474 if err != nil { 475 if aerr, ok := err.(awserr.Error); ok { 476 switch aerr.Code() { 477 case dynamodb.ErrCodeConditionalCheckFailedException: 478 fmt.Println(dynamodb.ErrCodeConditionalCheckFailedException, aerr.Error()) 479 case dynamodb.ErrCodeProvisionedThroughputExceededException: 480 fmt.Println(dynamodb.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 481 case dynamodb.ErrCodeResourceNotFoundException: 482 fmt.Println(dynamodb.ErrCodeResourceNotFoundException, aerr.Error()) 483 case dynamodb.ErrCodeItemCollectionSizeLimitExceededException: 484 fmt.Println(dynamodb.ErrCodeItemCollectionSizeLimitExceededException, aerr.Error()) 485 case dynamodb.ErrCodeTransactionConflictException: 486 fmt.Println(dynamodb.ErrCodeTransactionConflictException, aerr.Error()) 487 case dynamodb.ErrCodeRequestLimitExceeded: 488 fmt.Println(dynamodb.ErrCodeRequestLimitExceeded, aerr.Error()) 489 case dynamodb.ErrCodeInternalServerError: 490 fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) 491 default: 492 fmt.Println(aerr.Error()) 493 } 494 } else { 495 // Print the error, cast err to awserr.Error to get the Code and 496 // Message from an error. 497 fmt.Println(err.Error()) 498 } 499 return 500 } 501 502 fmt.Println(result) 503 } 504 505 // To query an item 506 // 507 // This example queries items in the Music table. The table has a partition key and 508 // sort key (Artist and SongTitle), but this query only specifies the partition key 509 // value. It returns song titles by the artist named "No One You Know". 510 func ExampleDynamoDB_Query_shared00() { 511 svc := dynamodb.New(session.New()) 512 input := &dynamodb.QueryInput{ 513 ExpressionAttributeValues: map[string]*dynamodb.AttributeValue{ 514 ":v1": { 515 S: aws.String("No One You Know"), 516 }, 517 }, 518 KeyConditionExpression: aws.String("Artist = :v1"), 519 ProjectionExpression: aws.String("SongTitle"), 520 TableName: aws.String("Music"), 521 } 522 523 result, err := svc.Query(input) 524 if err != nil { 525 if aerr, ok := err.(awserr.Error); ok { 526 switch aerr.Code() { 527 case dynamodb.ErrCodeProvisionedThroughputExceededException: 528 fmt.Println(dynamodb.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 529 case dynamodb.ErrCodeResourceNotFoundException: 530 fmt.Println(dynamodb.ErrCodeResourceNotFoundException, aerr.Error()) 531 case dynamodb.ErrCodeRequestLimitExceeded: 532 fmt.Println(dynamodb.ErrCodeRequestLimitExceeded, aerr.Error()) 533 case dynamodb.ErrCodeInternalServerError: 534 fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) 535 default: 536 fmt.Println(aerr.Error()) 537 } 538 } else { 539 // Print the error, cast err to awserr.Error to get the Code and 540 // Message from an error. 541 fmt.Println(err.Error()) 542 } 543 return 544 } 545 546 fmt.Println(result) 547 } 548 549 // To scan a table 550 // 551 // This example scans the entire Music table, and then narrows the results to songs 552 // by the artist "No One You Know". For each item, only the album title and song title 553 // are returned. 554 func ExampleDynamoDB_Scan_shared00() { 555 svc := dynamodb.New(session.New()) 556 input := &dynamodb.ScanInput{ 557 ExpressionAttributeNames: map[string]*string{ 558 "#AT": aws.String("AlbumTitle"), 559 "#ST": aws.String("SongTitle"), 560 }, 561 ExpressionAttributeValues: map[string]*dynamodb.AttributeValue{ 562 ":a": { 563 S: aws.String("No One You Know"), 564 }, 565 }, 566 FilterExpression: aws.String("Artist = :a"), 567 ProjectionExpression: aws.String("#ST, #AT"), 568 TableName: aws.String("Music"), 569 } 570 571 result, err := svc.Scan(input) 572 if err != nil { 573 if aerr, ok := err.(awserr.Error); ok { 574 switch aerr.Code() { 575 case dynamodb.ErrCodeProvisionedThroughputExceededException: 576 fmt.Println(dynamodb.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 577 case dynamodb.ErrCodeResourceNotFoundException: 578 fmt.Println(dynamodb.ErrCodeResourceNotFoundException, aerr.Error()) 579 case dynamodb.ErrCodeRequestLimitExceeded: 580 fmt.Println(dynamodb.ErrCodeRequestLimitExceeded, aerr.Error()) 581 case dynamodb.ErrCodeInternalServerError: 582 fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) 583 default: 584 fmt.Println(aerr.Error()) 585 } 586 } else { 587 // Print the error, cast err to awserr.Error to get the Code and 588 // Message from an error. 589 fmt.Println(err.Error()) 590 } 591 return 592 } 593 594 fmt.Println(result) 595 } 596 597 // To update an item in a table 598 // 599 // This example updates an item in the Music table. It adds a new attribute (Year) and 600 // modifies the AlbumTitle attribute. All of the attributes in the item, as they appear 601 // after the update, are returned in the response. 602 func ExampleDynamoDB_UpdateItem_shared00() { 603 svc := dynamodb.New(session.New()) 604 input := &dynamodb.UpdateItemInput{ 605 ExpressionAttributeNames: map[string]*string{ 606 "#AT": aws.String("AlbumTitle"), 607 "#Y": aws.String("Year"), 608 }, 609 ExpressionAttributeValues: map[string]*dynamodb.AttributeValue{ 610 ":t": { 611 S: aws.String("Louder Than Ever"), 612 }, 613 ":y": { 614 N: aws.String("2015"), 615 }, 616 }, 617 Key: map[string]*dynamodb.AttributeValue{ 618 "Artist": { 619 S: aws.String("Acme Band"), 620 }, 621 "SongTitle": { 622 S: aws.String("Happy Day"), 623 }, 624 }, 625 ReturnValues: aws.String("ALL_NEW"), 626 TableName: aws.String("Music"), 627 UpdateExpression: aws.String("SET #Y = :y, #AT = :t"), 628 } 629 630 result, err := svc.UpdateItem(input) 631 if err != nil { 632 if aerr, ok := err.(awserr.Error); ok { 633 switch aerr.Code() { 634 case dynamodb.ErrCodeConditionalCheckFailedException: 635 fmt.Println(dynamodb.ErrCodeConditionalCheckFailedException, aerr.Error()) 636 case dynamodb.ErrCodeProvisionedThroughputExceededException: 637 fmt.Println(dynamodb.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 638 case dynamodb.ErrCodeResourceNotFoundException: 639 fmt.Println(dynamodb.ErrCodeResourceNotFoundException, aerr.Error()) 640 case dynamodb.ErrCodeItemCollectionSizeLimitExceededException: 641 fmt.Println(dynamodb.ErrCodeItemCollectionSizeLimitExceededException, aerr.Error()) 642 case dynamodb.ErrCodeTransactionConflictException: 643 fmt.Println(dynamodb.ErrCodeTransactionConflictException, aerr.Error()) 644 case dynamodb.ErrCodeRequestLimitExceeded: 645 fmt.Println(dynamodb.ErrCodeRequestLimitExceeded, aerr.Error()) 646 case dynamodb.ErrCodeInternalServerError: 647 fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) 648 default: 649 fmt.Println(aerr.Error()) 650 } 651 } else { 652 // Print the error, cast err to awserr.Error to get the Code and 653 // Message from an error. 654 fmt.Println(err.Error()) 655 } 656 return 657 } 658 659 fmt.Println(result) 660 } 661 662 // To modify a table's provisioned throughput 663 // 664 // This example increases the provisioned read and write capacity on the Music table. 665 func ExampleDynamoDB_UpdateTable_shared00() { 666 svc := dynamodb.New(session.New()) 667 input := &dynamodb.UpdateTableInput{ 668 ProvisionedThroughput: &dynamodb.ProvisionedThroughput{ 669 ReadCapacityUnits: aws.Int64(10), 670 WriteCapacityUnits: aws.Int64(10), 671 }, 672 TableName: aws.String("MusicCollection"), 673 } 674 675 result, err := svc.UpdateTable(input) 676 if err != nil { 677 if aerr, ok := err.(awserr.Error); ok { 678 switch aerr.Code() { 679 case dynamodb.ErrCodeResourceInUseException: 680 fmt.Println(dynamodb.ErrCodeResourceInUseException, aerr.Error()) 681 case dynamodb.ErrCodeResourceNotFoundException: 682 fmt.Println(dynamodb.ErrCodeResourceNotFoundException, aerr.Error()) 683 case dynamodb.ErrCodeLimitExceededException: 684 fmt.Println(dynamodb.ErrCodeLimitExceededException, aerr.Error()) 685 case dynamodb.ErrCodeInternalServerError: 686 fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error()) 687 default: 688 fmt.Println(aerr.Error()) 689 } 690 } else { 691 // Print the error, cast err to awserr.Error to get the Code and 692 // Message from an error. 693 fmt.Println(err.Error()) 694 } 695 return 696 } 697 698 fmt.Println(result) 699 }