dynamodb.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package aws
  15. type DynamoDB struct {
  16. AttributeDefinitions []struct {
  17. AttributeName string `json:"AttributeName"`
  18. AttributeType string `json:"AttributeType"`
  19. } `json:"AttributeDefinitions"`
  20. BillingModeSummary struct {
  21. BillingMode string `json:"BillingMode"`
  22. LastUpdateToPayPerRequestDateTime float64 `json:"LastUpdateToPayPerRequestDateTime"`
  23. } `json:"BillingModeSummary"`
  24. CreationDateTime float64 `json:"CreationDateTime"`
  25. DeletionProtectionEnabled bool `json:"DeletionProtectionEnabled"`
  26. ItemCount int `json:"ItemCount"`
  27. KeySchema []struct {
  28. AttributeName string `json:"AttributeName"`
  29. KeyType string `json:"KeyType"`
  30. } `json:"KeySchema"`
  31. ProvisionedThroughput struct {
  32. NumberOfDecreasesToday int `json:"NumberOfDecreasesToday"`
  33. ReadCapacityUnits int `json:"ReadCapacityUnits"`
  34. WriteCapacityUnits int `json:"WriteCapacityUnits"`
  35. } `json:"ProvisionedThroughput"`
  36. TableArn string `json:"TableArn"`
  37. TableID string `json:"TableId"`
  38. TableName string `json:"TableName"`
  39. TableSizeBytes int `json:"TableSizeBytes"`
  40. TableStatus string `json:"TableStatus"`
  41. TableThroughputModeSummary struct {
  42. LastUpdateToPayPerRequestDateTime float64 `json:"LastUpdateToPayPerRequestDateTime"`
  43. TableThroughputMode string `json:"TableThroughputMode"`
  44. } `json:"TableThroughputModeSummary"`
  45. }
  46. func (self *SRegion) ListTables() ([]string, error) {
  47. params := map[string]interface{}{
  48. "Limit": 100,
  49. }
  50. ret := []string{}
  51. for {
  52. part := struct {
  53. TableNames []string
  54. LastEvaluatedTableName string
  55. }{}
  56. err := self.dynamodbRequest("ListTables", params, &part)
  57. if err != nil {
  58. return nil, err
  59. }
  60. ret = append(ret, part.TableNames...)
  61. if len(part.TableNames) == 0 || len(part.LastEvaluatedTableName) == 0 {
  62. break
  63. }
  64. params["ExclusiveStartTableName"] = part.LastEvaluatedTableName
  65. }
  66. return ret, nil
  67. }
  68. func (self *SRegion) DescribeTable(name string) (*DynamoDB, error) {
  69. params := map[string]interface{}{
  70. "TableName": name,
  71. }
  72. ret := struct {
  73. Table DynamoDB
  74. }{}
  75. err := self.dynamodbRequest("DescribeTable", params, &ret)
  76. if err != nil {
  77. return nil, err
  78. }
  79. return &ret.Table, nil
  80. }