{ "info": { "author": "Ajay A U", "author_email": "ajayau404@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.6" ], "description": "# AWS-ALB-lambda-python\n\nFramework for load-balancer and lambda function.\n\nTo learn more about writing AWS Lambda functions in python, go to [the official documentation](https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html)\n\nBlogs about AWS lambda and python is [here](https://aws.amazon.com/blogs/networking-and-content-delivery/lambda-functions-as-targets-for-application-load-balancers/)\n\n\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity)\n[![serverless](http://public.serverless.com/badges/v3.svg)](4)\n[![Pyhton-Lambda-Doc](https://img.shields.io/website-up-down-green-red/http/shields.io.svg)](1)\n[![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](5)\n[![PyPI version fury.io](https://badge.fury.io/py/ansicolortags.svg)](7)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/ansicolortags.svg)](2)\n[![Documentation Status](https://readthedocs.org/projects/ansicolortags/badge/?version=latest)](2)\n[![Documentation Status](https://readthedocs.org/projects/ansicolortags/badge/?version=latest)](3)\n[![Pyhton Lambda](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html)\n[![Build Status](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://travis-ci.org/joemccann/dillinger)\n\n[1]: https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html\n[2]: https://aws.amazon.com/blogs/networking-and-content-delivery/lambda-functions-as-targets-for-application-load-balancers/\n[3]: https://github.com/aws-samples/serverless-sinatra-sample\n[4]: https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html\n[5]: https://www.python.org/\n[6]: https://pypi.python.org/\n[7]: https://pypi.python.org/pypi/ajayau404/\n[8]: https://pypi.python.org/pypi/ansicolortags/\n\n# Getting Started\n\nThis is the AWS lambda framework written in python. When the lambda function is triggered by ALB or API-Gateway the event variable that contain all the required info will be sent to the init function. By default this init function will be in lambda_function.py and the name will be lambda_handler. This framework contains the request resource mappin for the URL and response that you have to send back to Load-Balancer.\n\nThe package information is in [Pypi info](https://pypi.org/project/py-lambda/)\n\n```\npip install py-lambda\n```\n\nThis source code contain the following files:\n* **lambda_function** : Contains the code that will be triggered by ALB or API-Gateway etc.\n* **request** : Contains the request object which is created from the event that is send as an input.\n* **response** : Contains the object that should be sent back from lambda function to ALB.\n* **lambda_mapping** : Is the file that contain the mapping for the routes. Add your routes in here.\n* **all_functions** : Contain the function contains the respective code that can be used for the given path.\n* **test_LambdaHandler** : Contains the test code that can be usedfortesting all the functions.\n\n### Load-Balancer input\n\n``` Python\n## test_LambdaHandler.py\nimport py_lambda.test_LambdaHandler as lTest\nprint(lTest.EVENT_FROM_ALB)\n```\n\nThe above code will give the sample of the request that will be send by ALB.\n\n### Mapping\n\n```Python\n## lambda_mapping.py\n\nFUNCT_MAPPING = {\n\t\"\": {\"\": allFun.index},\n\t\"test\": {\n\t\t\"\": allFun.test,\n\t\tld.URL_REST_ID_STR:{\n\t\t\t\"\": allFun.testUserId,\n\t\t},\n\t},\n\t\"abc\":{\n\t\t\"\": allFun.abc,\n\t},\n}\n```\n\nThis will have the mapping for each resources. The mapping is dictionary in which key is the URL resource and the value will be the function that you have to execute when the URL is called. The index URL in the mapping is the first one `\"\": {\"\": allFun.index}`. If all the function for the mapping are in `all_Functions.py` then corrponding function can be called in here.\n\nIf the resource contan some information that will change of each request then the mapping should contain `URL_REST_ID_STR` which is there in `lambda_defines.py` form wilch you will be able to map the URL. \n\nEg: \tmydomain.com/profile/USER_ID/image\nIn this `USER_ID` may change for each user. In that case use `URL_REST_ID_STR` in the mapping\n\n### Input validaation\n\n```python\n## inp_validatn.py\n## VALID_DOMAINS contains all the valid domains.\n## VALID_SUB_DOMAINS contails all the valid subdomains.\n\nimport py_lambda.funct_defines as funDef\n\nret_validation = validateDomain(\"http://some_domain.com\")\n##If the domain is valid then the function will return the success response\nif ret_validation[funDef.FUNCTION_STAT] == funDef.SUCCESS:\n\tprint(\"Valid domain\")\nelse:\n\tprint(\"invalid domain\")\n```\n\nInput validations can be adde in this function. `validateDomain` will validate the given domain and return success if it is valid.\n\n### Request\n\n```python\n## request.py\nimport py_lambda.request as Req\nimport py_lambda.test_LambdaHandler as lTest\nreqObj = Req.Request(lTest.EVENT_FROM_ALB)\n\nprint(\"Path Str:\",reqObj.getPathStr())\nprint(\"Req method:\",reqObj.httpMeth())\nprint(\"Req from ALB:\",reqObj.isAlb())\nprint(\"Cookies:\",reqObj.getCookies())\nprint(\"Query params by input list:\",reqObj.getQueryParams(['a']))\nprint(\"Query params all:\",reqObj.getAllQueryParam())\nprint(\"Base64 encooded:\",reqObj.isBase64())\n```\n\nWhen the request is sent to lambda function this request object object is created and we can use this to get all the information that we need like cookies, query parameters, headers etc from this.\n\n### Response\n\n```python\n## response.py\nimport py_lambda.response as Res\nrespObj = Res.Response()\nrespObj = Res.Response()\nprint(\"respObj:\", respObj())\nrespObj.setError()\nprint(\"respObj:\", respObj())\nrespObj.setResp()\nprint(\"respObj:\", respObj())\nrespObj.setResp(respBody={'a':1, 'b':2})\nprint(\"respObj:\", respObj())\n# respObj.setContentType(\"application/json\")\n# print(\"respObj:\", respObj())\nrespObj.setHeader(\"Access-Control-Allow-Origin\", \"*\")\nprint(\"respObj:\", respObj())\n```\n\nLoab-Balancer requer the response of the lambda function in a specific format. This response object is created when the function is invoked and this will be changed accordingly to send the reponse intended.\n\n### Lambda Function\n```python\n## lambda_function.py\n\nimport py_lambda.test_LambdaHandler as lTest\nimport py_lambda.lambda_function as lf\n\nRESOURCE_PREFIX = \"\"\nlTest.EVENT_FROM_ALB[\"path\"]= RESOURCE_PREFIX+'/abc'\nlTest.EVENT_FROM_ALB[\"httpMethod\"] = \"GET\"\n\nresp = lf.lambda_handler(event=lTest.EVENT_FROM_ALB,context= \"some_context\")\nprint(resp)\n```\n\nThis will give you the reponse if you have a mapping in `lambda_mapping.py`. body in the response will contain whatever you set in the response. Even you can set the header and the response code accordingly using `py_lambda.response.setResp` and `py_lambda.response.setHeader`\n\n### Testing\n\n```python\n## test_LambdaHandler.py\n\nimport py_lambda.test_LambdaHandler as lTest\nprint(lTest.testOptions())\n```\n\nThis contain all the testing function that are used to build this.\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ajayau404/AWS-Py-Lambda", "keywords": "", "license": "Apache License 2.0", "maintainer": "", "maintainer_email": "", "name": "py-lambda", "package_url": "https://pypi.org/project/py-lambda/", "platform": "", "project_url": "https://pypi.org/project/py-lambda/", "project_urls": { "Homepage": "https://github.com/ajayau404/AWS-Py-Lambda" }, "release_url": "https://pypi.org/project/py-lambda/1.1.5/", "requires_dist": [ "wheel", "setuptools" ], "requires_python": "", "summary": "Lambda framework for AWS", "version": "1.1.5" }, "last_serial": 5281756, "releases": { "1.1.0": [ { "comment_text": "", "digests": { "md5": "f9f1d0babf5f855996778815c8081315", "sha256": "8f97fe2cd15130a41acd5d01b57bd464ca264e7936af8e44ccdf53f20d36348d" }, "downloads": -1, "filename": "py_lambda-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "f9f1d0babf5f855996778815c8081315", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11169, "upload_time": "2019-05-15T18:08:45", "url": "https://files.pythonhosted.org/packages/60/9c/7b23b09cceb849c229bf8666ed7bc9c435f6d3ee7efc5369b63b7c896d1e/py_lambda-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8dc3f20ff60a4d89903aa5269dd82e0a", "sha256": "e44c31d637c1dae6a0c0af2aaed0b483c766f2081fdfe238542e555fcf6a563c" }, "downloads": -1, "filename": "py-lambda-1.1.0.tar.gz", "has_sig": false, "md5_digest": "8dc3f20ff60a4d89903aa5269dd82e0a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7582, "upload_time": "2019-05-15T18:08:48", "url": "https://files.pythonhosted.org/packages/dc/4c/529a005ca550d3443b56ff237ca3fe04cd9d07d9fbc5de7315e9380b0f9f/py-lambda-1.1.0.tar.gz" } ], "1.1.3": [ { "comment_text": "", "digests": { "md5": "47d53663e1d5dd16dff1c1ea43fc050e", "sha256": "342dc48bc0df68a71c61a56bbab49115a959ba4965aec0876c4960cb57fce78b" }, "downloads": -1, "filename": "py_lambda-1.1.3-py3-none-any.whl", "has_sig": false, "md5_digest": "47d53663e1d5dd16dff1c1ea43fc050e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11978, "upload_time": "2019-05-16T13:40:55", "url": "https://files.pythonhosted.org/packages/54/5e/162a64724a76e2e5ff3a88e1b371900ad69f865d8ecd292c4bb3ac257a7e/py_lambda-1.1.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0bfab8587d66c689582d64b05e368ace", "sha256": "e3723e497855725e31b3497a34c6679f04211bb045b542fbd75f1ee5f8852237" }, "downloads": -1, "filename": "py_lambda-1.1.3.tar.gz", "has_sig": false, "md5_digest": "0bfab8587d66c689582d64b05e368ace", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9020, "upload_time": "2019-05-16T13:40:57", "url": "https://files.pythonhosted.org/packages/16/a9/20667ca1c2d6cd3dd4e5685318468e80487db1fe20e2dd37806df92df982/py_lambda-1.1.3.tar.gz" } ], "1.1.4": [ { "comment_text": "", "digests": { "md5": "a1d47698901781c85bef0899bb0e4364", "sha256": "7d3969a79af09e74b8b2f9ed6afd0277157fea4ad822fc1703d873692125ff73" }, "downloads": -1, "filename": "py_lambda-1.1.4-py3-none-any.whl", "has_sig": false, "md5_digest": "a1d47698901781c85bef0899bb0e4364", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11977, "upload_time": "2019-05-17T10:56:14", "url": "https://files.pythonhosted.org/packages/ab/3a/600612d6ed0bbe7643a92e9f177ad1690f8053738867171312c169975c1a/py_lambda-1.1.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ed93710c8b73b8e0be82e264ac3c00d1", "sha256": "95ac9eac6e92760a35804a24cbb713da7c430074840483c39cd3d85a1ebd0caa" }, "downloads": -1, "filename": "py_lambda-1.1.4.tar.gz", "has_sig": false, "md5_digest": "ed93710c8b73b8e0be82e264ac3c00d1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9029, "upload_time": "2019-05-17T10:56:16", "url": "https://files.pythonhosted.org/packages/94/97/eddc822cc599a90a70d71adb29af4e6fdd4b4c54ef30f89bba2964078a9a/py_lambda-1.1.4.tar.gz" } ], "1.1.5": [ { "comment_text": "", "digests": { "md5": "3ec619cc8b102598a8f7fb4f7b50a12c", "sha256": "23683e5524fb9e11e8d226addb3d7fdf01744b93dede7e7dbba53de787aaf1cb" }, "downloads": -1, "filename": "py_lambda-1.1.5-py3-none-any.whl", "has_sig": false, "md5_digest": "3ec619cc8b102598a8f7fb4f7b50a12c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12672, "upload_time": "2019-05-17T10:58:40", "url": "https://files.pythonhosted.org/packages/79/0c/8abfef15f1aeeb2239cd048df43403717ac23f65f388a0dc47a0ca238714/py_lambda-1.1.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1d07179aa49ae47e22f8b663c621e9b9", "sha256": "bc73152971fe2d265b0fb717083804978fbcd416aa50844de1f3eabc890b4a0b" }, "downloads": -1, "filename": "py_lambda-1.1.5.tar.gz", "has_sig": false, "md5_digest": "1d07179aa49ae47e22f8b663c621e9b9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10858, "upload_time": "2019-05-17T10:58:41", "url": "https://files.pythonhosted.org/packages/bf/14/dc1fd6303229a864ff22e9552ddbba1b98bcf58b3856a5c5d10ffd669971/py_lambda-1.1.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3ec619cc8b102598a8f7fb4f7b50a12c", "sha256": "23683e5524fb9e11e8d226addb3d7fdf01744b93dede7e7dbba53de787aaf1cb" }, "downloads": -1, "filename": "py_lambda-1.1.5-py3-none-any.whl", "has_sig": false, "md5_digest": "3ec619cc8b102598a8f7fb4f7b50a12c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12672, "upload_time": "2019-05-17T10:58:40", "url": "https://files.pythonhosted.org/packages/79/0c/8abfef15f1aeeb2239cd048df43403717ac23f65f388a0dc47a0ca238714/py_lambda-1.1.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1d07179aa49ae47e22f8b663c621e9b9", "sha256": "bc73152971fe2d265b0fb717083804978fbcd416aa50844de1f3eabc890b4a0b" }, "downloads": -1, "filename": "py_lambda-1.1.5.tar.gz", "has_sig": false, "md5_digest": "1d07179aa49ae47e22f8b663c621e9b9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10858, "upload_time": "2019-05-17T10:58:41", "url": "https://files.pythonhosted.org/packages/bf/14/dc1fd6303229a864ff22e9552ddbba1b98bcf58b3856a5c5d10ffd669971/py_lambda-1.1.5.tar.gz" } ] }