Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for retrieving dynamodb resources #28

Merged
merged 1 commit into from
Oct 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions plumbum.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ def list_kinesis_applications(region, filter_by_kwargs):
kinesis_streams[stream_name] = shard_ids
return kinesis_streams

def list_dynamodb(region, filter_by_kwargs):
"""List all DynamoDB tables."""
conn = boto.dynamodb.connect_to_region(region)
tables = conn.list_tables()
return lookup(tables, filter_by=filter_by_kwargs)

list_resources = {
'ec2': list_ec2,
'elb': list_elb,
Expand All @@ -178,6 +184,7 @@ def list_kinesis_applications(region, filter_by_kwargs):
'asg': list_autoscaling_group,
'sqs': list_sqs,
'kinesisapp': list_kinesis_applications,
'dynamodb': list_dynamodb
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but in Python, I add trailing commas so future commits don't have to touch this line.

}


Expand Down
22 changes: 22 additions & 0 deletions sample_templates/dynamodb.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{%- set metrics = {'ConsumedReadCapacityUnits': {'stat': ['Minimum', 'Maximum', 'Sum', 'Average'], 'unit': 'Count'},
'ConsumedWriteCapacityUnits': {'stat': ['Minimum', 'Maximum', 'Sum', 'Average'], 'unit': 'Count'},
} -%}

# If connecting to a different region other than default, set region
Auth:
region: "{{ region }}"
Metrics:
{%- for table_name in resources %}
{%- for metric in metrics %}
- Namespace: "AWS/DynamoDB"
MetricName: "{{ metric }}"
Statistics: "{{ metrics[metric]['stat'] }}"
Unit: "{{ metrics[metric]['unit'] }}"
Dimensions:
TableName: "{{ table_name }}"
Options:
Formatter: 'cloudwatch.%(Namespace)s.{{ stream_name}}.%(MetricName)s.%(statistic)s.%(Unit)s'
Period: 1
{% endfor %}
{% endfor %}

6 changes: 6 additions & 0 deletions test_plumbum.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def test_filters_and_extras_with_region_specified(self):
self.assertEqual(len(filter_by), 1)
self.assertEqual(len(extras), 2)

def test_dynamodb_namespace(self):
argv = ['foo.j2', 'dynamodb', 'us-east-1']
templ, ns, region, filter_by, extras = plumbum.interpret_options(argv)
self.assertEqual(templ, 'foo.j2')
self.assertEqual(ns, 'dynamodb')
self.assertEqual(region, 'us-east-1')

if __name__ == '__main__':
unittest.main()