Skip to content

Instantly share code, notes, and snippets.

@jkielbaey
Created November 25, 2018 20:06
Show Gist options
  • Save jkielbaey/a560c2d9fc77dd0aaa73622d2010d216 to your computer and use it in GitHub Desktop.
Save jkielbaey/a560c2d9fc77dd0aaa73622d2010d216 to your computer and use it in GitHub Desktop.
import boto3
table_name = ‘sample_table’
ssm = boto3.client('ssm')
table = boto3.resource('dynamodb').Table(table_name)
# Store current read and write capacity units.
ssm.put_parameter(
Name=’/dynamodb/{}/read_capacity_units’.format(table_name),
Value=str(table.provisioned_throughput[‘ReadCapacityUnits’]),
Type='String',
Overwrite=True,
)
ssm.put_parameter(
Name=’/dynamodb/{}/write_capacity_units’.format(table_name),
Value=str(table.provisioned_throughput[‘WriteCapacityUnits’]),
Type='String',
Overwrite=True,
)
# Stop table.
table = table.update(
ProvisionedThroughput={
'ReadCapacityUnits': 0,
'WriteCapacityUnits': 0
})
# Fetch read and write capacity units.
response = ssm.get_parameter(
Name=’/dynamodb/{}/read_capacity_units’.format(table_name)
)
read_capacity_units = response[‘Parameter’][‘Value’]
response = ssm.get_parameter(
Name=’/dynamodb/{}/write_capacity_units’.format(table_name)
)
write_capacity_units = response[‘Parameter’][‘Value’]
table = table.update(
ProvisionedThroughput={
'ReadCapacityUnits': read_capacity_units,
'WriteCapacityUnits': write_capacity_units
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment