{"id":24435869,"url":"https://github.com/gabriele-mastrapasqua/serverless-lambda-flask","last_synced_at":"2025-12-30T03:24:40.259Z","repository":{"id":135547019,"uuid":"500328495","full_name":"gabriele-mastrapasqua/serverless-lambda-flask","owner":"gabriele-mastrapasqua","description":"Sample serverless framework lambda using flask and python 3.9","archived":false,"fork":false,"pushed_at":"2022-06-23T15:26:11.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-20T17:40:30.825Z","etag":null,"topics":["aws-lambda","flask","python3","serverless"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gabriele-mastrapasqua.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-06T07:09:38.000Z","updated_at":"2023-03-05T01:02:56.000Z","dependencies_parsed_at":"2023-09-18T02:28:35.082Z","dependency_job_id":null,"html_url":"https://github.com/gabriele-mastrapasqua/serverless-lambda-flask","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabriele-mastrapasqua%2Fserverless-lambda-flask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabriele-mastrapasqua%2Fserverless-lambda-flask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabriele-mastrapasqua%2Fserverless-lambda-flask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabriele-mastrapasqua%2Fserverless-lambda-flask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gabriele-mastrapasqua","download_url":"https://codeload.github.com/gabriele-mastrapasqua/serverless-lambda-flask/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243489829,"owners_count":20299001,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","flask","python3","serverless"],"created_at":"2025-01-20T17:35:29.820Z","updated_at":"2025-12-30T03:24:40.217Z","avatar_url":"https://github.com/gabriele-mastrapasqua.png","language":"Python","readme":"# python 3.9 Flask serverless lambda\nSample Serverless framework using API gateway that calls a lambda with python 3.9 with Flask.\n\n\n## prerequisites\nSetup the prerequisites:\n\n- python3 and virtualenv\n- nodejs: https://nodejs.org/en/download/\n- servless framework: \n```\nnpm install -g serverless\n```\n\n\n## setup and use a virtualenv\nSee also: https://www.infoworld.com/article/3239675/virtualenv-and-venv-python-virtual-environments-explained.html\n\n- setup a new virtualenv:\n```\nvirtualenv venv -p python3\n```\n\n- activate the virtualenv (unix / macos):\n```\n. venv/bin/activate\n```\n\nor on Windows using the Command Prompt:\n```\nvenv\\Scripts\\activate.bat\n```\n\n## setup flask support for lambda on serverless framework \n\ninstall (in the virtual env) the dependencies:\n```\npip install Flask\npip freeze \u003e requirements.txt\n```\n\n\n```\nsls plugin install -n serverless-wsgi\nsls plugin install -n serverless-python-requirements\n```\n\n## first time setup for serverless framework to work\non aws create a IAM user for programmatic access: https://www.serverless.com/framework/docs/providers/aws/guide/credentials/\n\n\n## change service name of the new api\nChange service name 'hello-world-lambda' in serverless.yml file with a new name.\n\n\n## local development (on port 5050)\n```\npython app.py\n```\n\n## Using Lambda custom url for direct access the lambda without api gateway\nUsing this new functionality will remove the max timeout of 30s from API Gateway.\nIf you want instead use an API GW, comment those lines and uncomment the lines above in serverless.yml.\n\n```\n# 1 - Enable direct Lambda Function URL, this can bypass API Gateway 30s timeout\n   url:\n     # Allow CORS for all requests from any origin\n     cors: true\n```\n\nSee also: https://www.serverless.com/blog/aws-lambda-function-urls-with-serverless-framework#:~:text=Unlike%20API%20Gateway%2C%20Function%20URLs,(up%20to%2015%20minutes).\n\n## Using Lambda through an api gateway\nThis will have max 30s timeout and more configuration options available.\nUncomment those lines in serverless.yml:\n\n```\n# 2 - Enable lambda through API Gateway HTTP API. Note, using API Gateway will force a 30s max timeout\n   # on all endpoints\n   #events:\n   #  - httpApi: '*'\n```\n\n## test sample endpoints \n\n```\ncurl  http://localhost:5050/ -H 'Content-Type: application/json' \ncurl  http://localhost:5050/quote -H 'Content-Type: application/json' \ncurl -X POST http://localhost:5050/testpost -H 'Content-Type: application/json' -d '{\"message\":\"this is a test!\"}'\n```\n\n\n## DEPLOY to AWS\n```\nexport AWS_ACCESS_KEY_ID=\u003cyour-key-here\u003e\nexport AWS_SECRET_ACCESS_KEY=\u003cyour-secret-key-here\u003e\nsls deploy\n```\n\nor in windows: \n```\nSET AWS_ACCESS_KEY_ID=\u003cyour-key-here\u003e\nSET AWS_SECRET_ACCESS_KEY=\u003cyour-secret-key-here\u003e\nsls deploy\n```\n\n\nafter some seconds it should prints an AWS api gateway url like this:\n\nhttps://XXXXXXX.execute-api.us-east-1.amazonaws.com/\n\nnow you can access your flask apis like GET 'https://XXXXXXX.execute-api.us-east-1.amazonaws.com/quote'!\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabriele-mastrapasqua%2Fserverless-lambda-flask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabriele-mastrapasqua%2Fserverless-lambda-flask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabriele-mastrapasqua%2Fserverless-lambda-flask/lists"}