From 3abdf55fb0d6019f63a456cb6d592ac1bc505f01 Mon Sep 17 00:00:00 2001
From: Patrick Cullen <patrick.cullen@washpost.com>
Date: Wed, 11 Oct 2017 20:40:09 -0400
Subject: [PATCH] added lambda tagging support

---
 setup.py         |  4 ++--
 tagger/tagger.py | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index 6a36492..407d64b 100644
--- a/setup.py
+++ b/setup.py
@@ -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=[
@@ -28,7 +28,7 @@
     author="Patrick Cullen and the WaPo platform tools team",
     author_email="opensource@washingtonpost.com",
     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 = []
 )
diff --git a/tagger/tagger.py b/tagger/tagger.py
index 4423737..efc3824 100644
--- a/tagger/tagger.py
+++ b/tagger/tagger.py
@@ -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 == "":
@@ -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