Skip to content

Commit

Permalink
added lambda tagging support
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbcullen committed Oct 12, 2017
1 parent 544596a commit 3abdf55
Show file tree
Hide file tree
Showing 2 changed files with 26 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.5.2',
version='0.6.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.5.2",
download_url = "https://github.com/washingtonpost/aws-tagger/tarball/v0.6.0",
keywords = ['tag', 'tagger', 'tagging', 'aws'],
classifiers = []
)
24 changes: 24 additions & 0 deletions tagger/tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(self, dryrun, verbose, role=None, region=None):
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)
self.taggers['lambda'] = LambdaTagger(dryrun, verbose, role=role, region=region)

def tag(self, resource_id, tags):
if resource_id == "":
Expand Down Expand Up @@ -275,6 +276,29 @@ def _dynamodb_tag_resource(self, **kwargs):
return self.dynamodb.tag_resource(**kwargs)


class LambdaTagger(object):
def __init__(self, dryrun, verbose, role=None, region=None):
self.dryrun = dryrun
self.verbose = verbose
self.alambda = _client('lambda', role=role, region=region)

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

#TODO @retry(retry_on_exception=_is_retryable_exception, stop_max_delay=30000, wait_exponential_multiplier=1000)
def _lambda_tag_resource(self, **kwargs):
return self.alambda.tag_resource(**kwargs)


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

0 comments on commit 3abdf55

Please sign in to comment.