{"id":17653035,"url":"https://github.com/anuradhawick/aws-lambda-serverless-boilerplate","last_synced_at":"2025-07-27T19:42:58.086Z","repository":{"id":94337099,"uuid":"243934398","full_name":"anuradhawick/aws-lambda-serverless-boilerplate","owner":"anuradhawick","description":"Boilerplate for AWS lambda deployment using serverless framework","archived":false,"fork":false,"pushed_at":"2021-05-31T01:51:12.000Z","size":16,"stargazers_count":24,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-07T08:03:41.982Z","etag":null,"topics":["aws","aws-lambda","boilerplate","db-hanlder","router","template"],"latest_commit_sha":null,"homepage":"https://towardsdatascience.com/serverless-a-painless-aws-boilerplate-e5ec3b4fb609","language":"JavaScript","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/anuradhawick.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":"2020-02-29T08:46:59.000Z","updated_at":"2023-04-03T21:21:02.000Z","dependencies_parsed_at":"2023-03-14T14:30:22.038Z","dependency_job_id":null,"html_url":"https://github.com/anuradhawick/aws-lambda-serverless-boilerplate","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/anuradhawick%2Faws-lambda-serverless-boilerplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anuradhawick%2Faws-lambda-serverless-boilerplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anuradhawick%2Faws-lambda-serverless-boilerplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anuradhawick%2Faws-lambda-serverless-boilerplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anuradhawick","download_url":"https://codeload.github.com/anuradhawick/aws-lambda-serverless-boilerplate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252839287,"owners_count":21812086,"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","aws-lambda","boilerplate","db-hanlder","router","template"],"created_at":"2024-10-23T11:49:45.909Z","updated_at":"2025-05-07T08:03:48.231Z","avatar_url":"https://github.com/anuradhawick.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aws-lambda-serverless-boilerplate\nAn easy to use scalable boilerplate for AWS serverless deployment. Contains key artifacts;\n1. Router\n2. Multiple service handling\n3. Database connector\n4. Offline Runner  \n\nRead the blog in [Medium](https://towardsdatascience.com/serverless-a-painless-aws-boilerplate-e5ec3b4fb609)\n\n## Adding services\n\n* Create a folder for service\n* Create a `service.yml` inside it\n* Make necessary modifications like below\n```yaml\n# packages to include\npackage:\n  # exclude all folders and files\n  exclude:\n    - '**/*'\n  # include all that is relevant to the service\n  include:\n    - node_modules/**\n    - utils/**\n    - second-service/**\n\nservice: second-service\n\nfunctions:\n  second-service:\n    handler: second-service/second-main.main\n    name:  ${self:service}-${opt:stage}\n    environment:\n      MONGODB_ATLAS_CLUSTER_URI: ${self:custom.env.MONGODB_ATLAS_CLUSTER_URI}\n      user_pool_id: ${self:custom.config.user_pool_id}\n      BUCKET_NAME: ${self:custom.env.BUCKET_NAME}\n      BUCKET_REGION: ${self:custom.env.BUCKET_REGION}\n    events:\n      - http:\n          # implementing GET request to the end point /users of second service.\n          # note that we do not have base path PATH1 here since it is not requires as we\n          # are already in service of PATH1\n          method: get\n          path: users\n          cors: true\n          # Example authorization with a user pool\n          authorizer:\n            name: vinyl-authorizer\n            arn:  ${self:custom.config.userpool_authorizer_arn}\n```\n* Deploy using command\n\n`serverless deploy --stage STAGE --service SERVICE_FOLDER`\n\n## Using Router\n\n```js\n\n// create router instance\nconst router = new lambdaRouter.Router(event, context, callback);\n\n// calling route method\n// acts as a switch case, pass method, path template string and a handler\n// call this router.route function as many times as you like with your methods and paths\n// for readability you could implement the function logic in a separate functions file as I have done\nrouter.route(\n    'GET',\n    '/data',\n    (event, context, callback) =\u003e {\n        first_functions.data(event.queryStringParameters).then((data) =\u003e {\n            callback(null, lambdaRouter.builResponse(200, {\n                ...data,\n                success: true\n            }))\n            }).catch((e) =\u003e {\n                console.error(e);\n                callback(null, lambdaRouter.builResponse(\n                        500,  \n                        {\n                            records: \"ERROR\",\n                            success: false\n                        })\n                    );\n                }\n            );\n        }\n```\n\n## Using DB Connection\n\n* The DB hanlder supports MongoDB\n* Simply import the DB hanlder and call connect function.\n\n```js\nconst db_util = require(\"../utils/db-util\");\n\nconst db = await db_util.connect_db(); // returns a promise\n```\n\n## Testing offline\n\n* Once a new service is registerd modify the `offline-serverless.js` files services array as follows.\n\n```js\nconst services = [\n  {route:/^\\/PATH1/, path:'first-service', port:3001},\n  {route:/^\\/PATH2/, path:'second-service', port:3002},\n  {route:/^\\/NEW_PATH/, path:'new-service', port:3003}  // \u003c- New service, new port\n];\n```\n\n* Use command\n\n`node offline-serverless.js`\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanuradhawick%2Faws-lambda-serverless-boilerplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanuradhawick%2Faws-lambda-serverless-boilerplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanuradhawick%2Faws-lambda-serverless-boilerplate/lists"}