Skip to content

Commit 28c7a2a

Browse files
flemchbchew
authored andcommitted
fix: allow restore on-demand mode database (#311)
Fix KeyError: 'ProvisionedThroughput' which occurs when trying to restore a DynamoDB which is in on-demand mode.
1 parent dc12c58 commit 28c7a2a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

dynamodump/dynamodump.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ def prepare_gsi_for_restore(gsi, billing_mode):
822822
"Projection": gsi["Projection"],
823823
}
824824

825-
if billing_mode != PAY_PER_REQUEST_BILLING_MODE:
825+
if billing_mode != PAY_PER_REQUEST_BILLING_MODE and "ProvisionedThroughput" in gsi:
826826
result["ProvisionedThroughput"] = prepare_provisioned_throughput_for_restore(
827827
gsi["ProvisionedThroughput"]
828828
)
@@ -900,6 +900,9 @@ def do_restore(
900900
original_gsi_read_capacities = []
901901
if table_global_secondary_indexes is not None:
902902
for gsi in table_global_secondary_indexes:
903+
if "ProvisionedThroughput" not in gsi:
904+
continue
905+
903906
# keeps track of original gsi write capacity units. If provisioned capacity is 0, set to
904907
# RESTORE_WRITE_CAPACITY as fallback given that 0 is not allowed for write capacities
905908
original_gsi_write_capacity = gsi["ProvisionedThroughput"][
@@ -1065,6 +1068,9 @@ def do_restore(
10651068
if table_global_secondary_indexes is not None:
10661069
gsi_data = []
10671070
for gsi in table_global_secondary_indexes:
1071+
if "ProvisionedThroughput" not in gsi:
1072+
continue
1073+
10681074
wcu = gsi["ProvisionedThroughput"]["WriteCapacityUnits"]
10691075
rcu = gsi["ProvisionedThroughput"]["ReadCapacityUnits"]
10701076
original_gsi_write_capacity = original_gsi_write_capacities.pop(0)

0 commit comments

Comments
 (0)