{"action":"created","comment":{"url":"https://api.github.com/repos/adamchainz/dynamodb_utils/pulls/comments/100665166","pull_request_review_id":21383725,"id":100665166,"diff_hunk":"@@ -0,0 +1,71 @@\n+from __future__ import absolute_import\n+\n+import importlib\n+import json\n+import logging\n+import os\n+\n+from pynamodb.connection import Connection\n+\n+from . import dumper\n+from .multi import awslambda\n+\n+logger = logging.getLogger(__name__)\n+\n+def handler(event, context):\n+    if not isinstance(event, dict):\n+        logger.error('event not a dict')\n+        return\n+\n+    source = event.get('source', None)\n+\n+    if source == dumper.__name__:\n+        tables = []\n+        table = event.get('table', '*')\n+        dest = event.get('destination', None)\n+        config = event.get('config', {'region': os.environ.get('AWS_REGION', None)})\n+\n+        if not dest:\n+            logger.error('Destination not found in event!')\n+            return\n+\n+        if table == '*':\n+            try:\n+                connection = Connection(host=config.get('host', None), region=config.get('region', None))\n+                tables = connection.list_tables().get('TableNames', [])\n+            except Exception as e:\n+                logger.error('Failed to list tables to be backed up: {0}'.format(e))\n+        else:\n+            tables = re.split('\\s+/', source)\n+\n+        if not tables:\n+            logger.error('No tables to back up!')\n+            return\n+\n+        for table in tables:\n+            try:\n+                logger.debug('Dumping table {0} to {1} with config {2}'.format(table, dest, config))\n+                dumper.dump_table(table_name=table, destination=dest, **config)\n+            except Exception as e:\n+                logger.error('Failed to dump table {0} to {1}: {2}'.format(table, dest, e))\n+\n+    elif source == awslambda.__name__:\n+        args = event.get('args', [])\n+        target = event.get('target', {})\n+        module = target.get('module', None)\n+        name = target.get('name', None)\n+\n+        if module and name:\n+            mod = importlib.import_module(module)\n+            func = getattr(mod, name, None)\n+            if callable(func):\n+                logger.debug('Calling function: {0}'.format(func))\n+                func(*args)\n+            else:\n+                logger.error('Selected function is not callable: {0}.{1}'.format(module, name))\n+        else:\n+            logger.error('Target module and/or name not found in event!')","path":"dynamodb_utils/awslambda.py","position":67,"original_position":67,"commit_id":"961f4b557bb2bc54419be85e84b47d0935ae0873","original_commit_id":"961f4b557bb2bc54419be85e84b47d0935ae0873","user":{"login":"adamchainz","id":857609,"avatar_url":"https://avatars.githubusercontent.com/u/857609?v=3","gravatar_id":"","url":"https://api.github.com/users/adamchainz","html_url":"https://github.com/adamchainz","followers_url":"https://api.github.com/users/adamchainz/followers","following_url":"https://api.github.com/users/adamchainz/following{/other_user}","gists_url":"https://api.github.com/users/adamchainz/gists{/gist_id}","starred_url":"https://api.github.com/users/adamchainz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamchainz/subscriptions","organizations_url":"https://api.github.com/users/adamchainz/orgs","repos_url":"https://api.github.com/users/adamchainz/repos","events_url":"https://api.github.com/users/adamchainz/events{/privacy}","received_events_url":"https://api.github.com/users/adamchainz/received_events","type":"User","site_admin":false},"body":"again probably too defensive and better to just do things like `event['module']` and `func(*args)`\r\n\r\nstack traces provide more information than your debug messages :)","created_at":"2017-02-11T10:46:30Z","updated_at":"2017-02-11T10:48:36Z","html_url":"https://github.com/adamchainz/dynamodb_utils/pull/14#discussion_r100665166","pull_request_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/pulls/14","_links":{"self":{"href":"https://api.github.com/repos/adamchainz/dynamodb_utils/pulls/comments/100665166"},"html":{"href":"https://github.com/adamchainz/dynamodb_utils/pull/14#discussion_r100665166"},"pull_request":{"href":"https://api.github.com/repos/adamchainz/dynamodb_utils/pulls/14"}}},"pull_request":{"url":"https://api.github.com/repos/adamchainz/dynamodb_utils/pulls/14","id":104697032,"html_url":"https://github.com/adamchainz/dynamodb_utils/pull/14","diff_url":"https://github.com/adamchainz/dynamodb_utils/pull/14.diff","patch_url":"https://github.com/adamchainz/dynamodb_utils/pull/14.patch","issue_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/issues/14","number":14,"state":"open","locked":false,"title":"Add modular IO and Multiprocess back-ends","user":{"login":"brandond","id":370103,"avatar_url":"https://avatars.githubusercontent.com/u/370103?v=3","gravatar_id":"","url":"https://api.github.com/users/brandond","html_url":"https://github.com/brandond","followers_url":"https://api.github.com/users/brandond/followers","following_url":"https://api.github.com/users/brandond/following{/other_user}","gists_url":"https://api.github.com/users/brandond/gists{/gist_id}","starred_url":"https://api.github.com/users/brandond/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brandond/subscriptions","organizations_url":"https://api.github.com/users/brandond/orgs","repos_url":"https://api.github.com/users/brandond/repos","events_url":"https://api.github.com/users/brandond/events{/privacy}","received_events_url":"https://api.github.com/users/brandond/received_events","type":"User","site_admin":false},"body":"Takes care of #6 ","created_at":"2017-02-05T11:47:44Z","updated_at":"2017-02-11T10:48:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"229756262e083b20066f975b46946a422bb0536c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/pulls/14/commits","review_comments_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/pulls/14/comments","review_comment_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/pulls/comments{/number}","comments_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/issues/14/comments","statuses_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/statuses/961f4b557bb2bc54419be85e84b47d0935ae0873","head":{"label":"brandond:modular_io","ref":"modular_io","sha":"961f4b557bb2bc54419be85e84b47d0935ae0873","user":{"login":"brandond","id":370103,"avatar_url":"https://avatars.githubusercontent.com/u/370103?v=3","gravatar_id":"","url":"https://api.github.com/users/brandond","html_url":"https://github.com/brandond","followers_url":"https://api.github.com/users/brandond/followers","following_url":"https://api.github.com/users/brandond/following{/other_user}","gists_url":"https://api.github.com/users/brandond/gists{/gist_id}","starred_url":"https://api.github.com/users/brandond/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brandond/subscriptions","organizations_url":"https://api.github.com/users/brandond/orgs","repos_url":"https://api.github.com/users/brandond/repos","events_url":"https://api.github.com/users/brandond/events{/privacy}","received_events_url":"https://api.github.com/users/brandond/received_events","type":"User","site_admin":false},"repo":{"id":80501919,"name":"dynamodb_utils","full_name":"brandond/dynamodb_utils","owner":{"login":"brandond","id":370103,"avatar_url":"https://avatars.githubusercontent.com/u/370103?v=3","gravatar_id":"","url":"https://api.github.com/users/brandond","html_url":"https://github.com/brandond","followers_url":"https://api.github.com/users/brandond/followers","following_url":"https://api.github.com/users/brandond/following{/other_user}","gists_url":"https://api.github.com/users/brandond/gists{/gist_id}","starred_url":"https://api.github.com/users/brandond/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brandond/subscriptions","organizations_url":"https://api.github.com/users/brandond/orgs","repos_url":"https://api.github.com/users/brandond/repos","events_url":"https://api.github.com/users/brandond/events{/privacy}","received_events_url":"https://api.github.com/users/brandond/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/brandond/dynamodb_utils","description":"A toolchain for Amazon's DynamoDB to make common operations (backup, restore backups) easier.","fork":true,"url":"https://api.github.com/repos/brandond/dynamodb_utils","forks_url":"https://api.github.com/repos/brandond/dynamodb_utils/forks","keys_url":"https://api.github.com/repos/brandond/dynamodb_utils/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brandond/dynamodb_utils/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brandond/dynamodb_utils/teams","hooks_url":"https://api.github.com/repos/brandond/dynamodb_utils/hooks","issue_events_url":"https://api.github.com/repos/brandond/dynamodb_utils/issues/events{/number}","events_url":"https://api.github.com/repos/brandond/dynamodb_utils/events","assignees_url":"https://api.github.com/repos/brandond/dynamodb_utils/assignees{/user}","branches_url":"https://api.github.com/repos/brandond/dynamodb_utils/branches{/branch}","tags_url":"https://api.github.com/repos/brandond/dynamodb_utils/tags","blobs_url":"https://api.github.com/repos/brandond/dynamodb_utils/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brandond/dynamodb_utils/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brandond/dynamodb_utils/git/refs{/sha}","trees_url":"https://api.github.com/repos/brandond/dynamodb_utils/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brandond/dynamodb_utils/statuses/{sha}","languages_url":"https://api.github.com/repos/brandond/dynamodb_utils/languages","stargazers_url":"https://api.github.com/repos/brandond/dynamodb_utils/stargazers","contributors_url":"https://api.github.com/repos/brandond/dynamodb_utils/contributors","subscribers_url":"https://api.github.com/repos/brandond/dynamodb_utils/subscribers","subscription_url":"https://api.github.com/repos/brandond/dynamodb_utils/subscription","commits_url":"https://api.github.com/repos/brandond/dynamodb_utils/commits{/sha}","git_commits_url":"https://api.github.com/repos/brandond/dynamodb_utils/git/commits{/sha}","comments_url":"https://api.github.com/repos/brandond/dynamodb_utils/comments{/number}","issue_comment_url":"https://api.github.com/repos/brandond/dynamodb_utils/issues/comments{/number}","contents_url":"https://api.github.com/repos/brandond/dynamodb_utils/contents/{+path}","compare_url":"https://api.github.com/repos/brandond/dynamodb_utils/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brandond/dynamodb_utils/merges","archive_url":"https://api.github.com/repos/brandond/dynamodb_utils/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brandond/dynamodb_utils/downloads","issues_url":"https://api.github.com/repos/brandond/dynamodb_utils/issues{/number}","pulls_url":"https://api.github.com/repos/brandond/dynamodb_utils/pulls{/number}","milestones_url":"https://api.github.com/repos/brandond/dynamodb_utils/milestones{/number}","notifications_url":"https://api.github.com/repos/brandond/dynamodb_utils/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brandond/dynamodb_utils/labels{/name}","releases_url":"https://api.github.com/repos/brandond/dynamodb_utils/releases{/id}","deployments_url":"https://api.github.com/repos/brandond/dynamodb_utils/deployments","created_at":"2017-01-31T08:07:22Z","updated_at":"2017-01-31T08:07:24Z","pushed_at":"2017-02-08T01:02:45Z","git_url":"git://github.com/brandond/dynamodb_utils.git","ssh_url":"git@github.com:brandond/dynamodb_utils.git","clone_url":"https://github.com/brandond/dynamodb_utils.git","svn_url":"https://github.com/brandond/dynamodb_utils","homepage":"","size":49,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"adamchainz:master","ref":"master","sha":"aabf1a56c88b06ac7e5fced75b08370cca1ab1e2","user":{"login":"adamchainz","id":857609,"avatar_url":"https://avatars.githubusercontent.com/u/857609?v=3","gravatar_id":"","url":"https://api.github.com/users/adamchainz","html_url":"https://github.com/adamchainz","followers_url":"https://api.github.com/users/adamchainz/followers","following_url":"https://api.github.com/users/adamchainz/following{/other_user}","gists_url":"https://api.github.com/users/adamchainz/gists{/gist_id}","starred_url":"https://api.github.com/users/adamchainz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamchainz/subscriptions","organizations_url":"https://api.github.com/users/adamchainz/orgs","repos_url":"https://api.github.com/users/adamchainz/repos","events_url":"https://api.github.com/users/adamchainz/events{/privacy}","received_events_url":"https://api.github.com/users/adamchainz/received_events","type":"User","site_admin":false},"repo":{"id":16462191,"name":"dynamodb_utils","full_name":"adamchainz/dynamodb_utils","owner":{"login":"adamchainz","id":857609,"avatar_url":"https://avatars.githubusercontent.com/u/857609?v=3","gravatar_id":"","url":"https://api.github.com/users/adamchainz","html_url":"https://github.com/adamchainz","followers_url":"https://api.github.com/users/adamchainz/followers","following_url":"https://api.github.com/users/adamchainz/following{/other_user}","gists_url":"https://api.github.com/users/adamchainz/gists{/gist_id}","starred_url":"https://api.github.com/users/adamchainz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamchainz/subscriptions","organizations_url":"https://api.github.com/users/adamchainz/orgs","repos_url":"https://api.github.com/users/adamchainz/repos","events_url":"https://api.github.com/users/adamchainz/events{/privacy}","received_events_url":"https://api.github.com/users/adamchainz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/adamchainz/dynamodb_utils","description":"A toolchain for Amazon's DynamoDB to make common operations (backup, restore backups) easier.","fork":false,"url":"https://api.github.com/repos/adamchainz/dynamodb_utils","forks_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/forks","keys_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/keys{/key_id}","collaborators_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/teams","hooks_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/hooks","issue_events_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/issues/events{/number}","events_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/events","assignees_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/assignees{/user}","branches_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/branches{/branch}","tags_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/tags","blobs_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/git/refs{/sha}","trees_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/git/trees{/sha}","statuses_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/statuses/{sha}","languages_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/languages","stargazers_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/stargazers","contributors_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/contributors","subscribers_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/subscribers","subscription_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/subscription","commits_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/commits{/sha}","git_commits_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/git/commits{/sha}","comments_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/comments{/number}","issue_comment_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/issues/comments{/number}","contents_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/contents/{+path}","compare_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/compare/{base}...{head}","merges_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/merges","archive_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/downloads","issues_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/issues{/number}","pulls_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/pulls{/number}","milestones_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/milestones{/number}","notifications_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/labels{/name}","releases_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/releases{/id}","deployments_url":"https://api.github.com/repos/adamchainz/dynamodb_utils/deployments","created_at":"2014-02-02T20:15:39Z","updated_at":"2017-02-01T20:43:56Z","pushed_at":"2017-02-08T01:02:46Z","git_url":"git://github.com/adamchainz/dynamodb_utils.git","ssh_url":"git@github.com:adamchainz/dynamodb_utils.git","clone_url":"https://github.com/adamchainz/dynamodb_utils.git","svn_url":"https://github.com/adamchainz/dynamodb_utils","homepage":"","size":42,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":6,"forks":4,"open_issues":6,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/adamchainz/dynamodb_utils/pulls/14"},"html":{"href":"https://github.com/adamchainz/dynamodb_utils/pull/14"},"issue":{"href":"https://api.github.com/repos/adamchainz/dynamodb_utils/issues/14"},"comments":{"href":"https://api.github.com/repos/adamchainz/dynamodb_utils/issues/14/comments"},"review_comments":{"href":"https://api.github.com/repos/adamchainz/dynamodb_utils/pulls/14/comments"},"review_comment":{"href":"https://api.github.com/repos/adamchainz/dynamodb_utils/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/adamchainz/dynamodb_utils/pulls/14/commits"},"statuses":{"href":"https://api.github.com/repos/adamchainz/dynamodb_utils/statuses/961f4b557bb2bc54419be85e84b47d0935ae0873"}}}}
{"actor":{"display_login":"adamchainz"}}