{"action":"opened","issue":{"url":"https://api.github.com/repos/nficano/python-lambda/issues/120","repository_url":"https://api.github.com/repos/nficano/python-lambda","labels_url":"https://api.github.com/repos/nficano/python-lambda/issues/120/labels{/name}","comments_url":"https://api.github.com/repos/nficano/python-lambda/issues/120/comments","events_url":"https://api.github.com/repos/nficano/python-lambda/issues/120/events","html_url":"https://github.com/nficano/python-lambda/issues/120","id":348241587,"node_id":"MDU6SXNzdWUzNDgyNDE1ODc=","number":120,"title":"Building from a non-working directory does not include any files into the bundle","user":{"login":"Birne94","id":617722,"node_id":"MDQ6VXNlcjYxNzcyMg==","avatar_url":"https://avatars3.githubusercontent.com/u/617722?v=4","gravatar_id":"","url":"https://api.github.com/users/Birne94","html_url":"https://github.com/Birne94","followers_url":"https://api.github.com/users/Birne94/followers","following_url":"https://api.github.com/users/Birne94/following{/other_user}","gists_url":"https://api.github.com/users/Birne94/gists{/gist_id}","starred_url":"https://api.github.com/users/Birne94/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Birne94/subscriptions","organizations_url":"https://api.github.com/users/Birne94/orgs","repos_url":"https://api.github.com/users/Birne94/repos","events_url":"https://api.github.com/users/Birne94/events{/privacy}","received_events_url":"https://api.github.com/users/Birne94/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-07T09:32:59Z","updated_at":"2018-08-07T09:32:59Z","closed_at":null,"author_association":"NONE","body":"We are using one repository which includes multiple lambda configurations.\r\n\r\n```\r\n/dummy\r\n\tconfig-1.yaml\r\n\tconfig-2.yaml\r\n\thandler.py\r\n\trequirements.txt\r\n/foo\r\n\tconfig.yaml\r\n\thandler.py\r\n\trequirements.txt\r\n```\r\n\r\n I created a little script to create packages for each of the functions:\r\n```python\r\n#!/usr/bin/env python\r\n\r\nimport aws_lambda\r\nimport os\r\n\r\n_cwd = os.getcwd()\r\n\r\n\r\ndef build(name, config='config.yaml'):\r\n    aws_lambda.build(\r\n        os.path.join(_cwd, name),\r\n        requirements=os.path.join(_cwd, name, 'requirements.txt'),\r\n        config_file=os.path.join(_cwd, name, config)\r\n    )\r\n\r\n\r\nbuild('dummy', 'config-1.yaml')\r\nbuild('dummy', 'config-2.yaml')\r\nbuild('foo')\r\n\r\n```\r\n\r\nThe resulting packages only contain the installed requirements, but not any of the lambda handler itself.\r\n\r\nThis is caused by the [`isfile` check in `aws_lambda.build`](https://github.com/nficano/python-lambda/blob/0b02ec519d2ba0b18930284e55e621c578655b09/aws_lambda/aws_lambda.py#L330). It assumes that the current directory is the source directory since it does not join the directory and filename (as done 6 lines below).\r\n\r\npossible fix:\r\n\r\n```diff\r\n--- /tmp/a\t2018-08-07 11:28:35.000000000 +0200\r\n+++ /tmp/b\t2018-08-07 11:28:40.000000000 +0200\r\n@@ -327,16 +327,17 @@\r\n \r\n     files = []\r\n     for filename in os.listdir(src):\r\n-        if os.path.isfile(filename):\r\n+        abs_filename = os.path.join(src, filename)\r\n+        if os.path.isfile(abs_filename):\r\n             if filename == '.DS_Store':\r\n                 continue\r\n             if filename == config_file:\r\n                 continue\r\n             print('Bundling: %r' % filename)\r\n-            files.append(os.path.join(src, filename))\r\n+            files.append(abs_filename)\r\n         elif os.path.isdir(filename) and filename in source_directories:\r\n             print('Bundling directory: %r' % filename)\r\n-            files.append(os.path.join(src, filename))\r\n+            files.append(abs_filename)\r\n \r\n     # \"cd\" into `temp_path` directory.\r\n     os.chdir(path_to_temp)\r\n\r\n```"}}
{"actor":{"display_login":"Birne94"}}