Skip to content

Commit

Permalink
added support for dynamodb tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbcullen committed Feb 3, 2017
1 parent 39305f6 commit 72a063d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='aws-tagger',
version='0.3.0',
version='0.4.0',
packages=find_packages(),
include_package_data=True,
install_requires=[
Expand All @@ -28,7 +28,7 @@
author="Patrick Cullen and the WaPo platform tools team",
author_email="[email protected]",
url="https://github.com/washingtonpost/aws-tagger",
download_url = "https://github.com/washingtonpost/aws-tagger/tarball/v0.3.0",
download_url = "https://github.com/washingtonpost/aws-tagger/tarball/v0.4.0",
keywords = ['tag', 'tagger', 'tagging', 'aws'],
classifiers = []
)
25 changes: 25 additions & 0 deletions tagger/tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self, dryrun, verbose, role=None, region=None):
self.taggers['kinesis'] = KinesisTagger(dryrun, verbose, role=role, region=region)
self.taggers['cloudfront'] = CloudfrontTagger(dryrun, verbose, role=role, region=region)
self.taggers['logs'] = CloudWatchLogsTagger(dryrun, verbose, role=role, region=region)
self.taggers['dynamodb'] = DynamoDBTagger(dryrun, verbose, role=role, region=region)

def tag(self, resource_id, tags):
if resource_id == "":
Expand Down Expand Up @@ -230,6 +231,30 @@ def tag(self, resource_arn, tags):
def _efs_create_tags(self, **kwargs):
return self.efs.create_tags(**kwargs)

class DynamoDBTagger(object):
def __init__(self, dryrun, verbose, role=None, region=None):
self.dryrun = dryrun
self.verbose = verbose
self.dynamodb = _client('dynamodb', role=role, region=region)

def tag(self, resource_arn, tags):
aws_tags = _dict_to_aws_tags(tags)
if self.verbose:
print "tagging %s with %s" % (resource_arn, _format_dict(tags))
if not self.dryrun:
try:
self._dynamodb_tag_resource(ResourceArn=resource_arn, Tags=aws_tags)
except botocore.exceptions.ClientError as exception:
if exception.response["Error"]["Code"] in ['ResourceNotFoundException']:
print "Resource not found: %s" % resource_arn
else:
raise exception

@retry(retry_on_exception=_is_retryable_exception, stop_max_delay=30000, wait_exponential_multiplier=1000)
def _dynamodb_tag_resource(self, **kwargs):
return self.dynamodb.tag_resource(**kwargs)


class CloudWatchLogsTagger(object):
def __init__(self, dryrun, verbose, role=None, region=None):
self.dryrun = dryrun
Expand Down

0 comments on commit 72a063d

Please sign in to comment.