{"id":15322815,"url":"https://github.com/msfidelis/serverless-architecture-boilerplate","last_synced_at":"2025-04-05T18:08:55.625Z","repository":{"id":29262470,"uuid":"108043859","full_name":"msfidelis/serverless-architecture-boilerplate","owner":"msfidelis","description":":package: :zap:  :rocket:  Boilerplate to organize and deploy big projects using AWS API Gateway and AWS Lambda with Serverless Framework","archived":false,"fork":false,"pushed_at":"2023-01-06T01:36:08.000Z","size":491,"stargazers_count":390,"open_issues_count":6,"forks_count":62,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-03-29T17:09:27.063Z","etag":null,"topics":["aws","aws-lambda","boilerplate","nodejs","python","serverless"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/msfidelis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-23T21:48:19.000Z","updated_at":"2024-09-02T19:34:07.000Z","dependencies_parsed_at":"2023-01-14T14:32:05.621Z","dependency_job_id":null,"html_url":"https://github.com/msfidelis/serverless-architecture-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/msfidelis%2Fserverless-architecture-boilerplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msfidelis%2Fserverless-architecture-boilerplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msfidelis%2Fserverless-architecture-boilerplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msfidelis%2Fserverless-architecture-boilerplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msfidelis","download_url":"https://codeload.github.com/msfidelis/serverless-architecture-boilerplate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247378149,"owners_count":20929297,"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","nodejs","python","serverless"],"created_at":"2024-10-01T09:18:10.541Z","updated_at":"2025-04-05T18:08:55.605Z","avatar_url":"https://github.com/msfidelis.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Logo](https://cdn-images-1.medium.com/max/1600/1*OezhU9lHTNCk6O6FCUL5fQ.png)\n\n\n# Serverless Architecture Boilerplate [![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Build Status](https://travis-ci.org/msfidelis/serverless-architecture-boilerplate.svg?branch=master)](https://travis-ci.org/msfidelis/serverless-architecture-boilerplate)\n\n## CI / CD Pipeline\n\nNeed a Codepipeline Structure to deploy your Serverless Project with Quality? [See this repo](https://github.com/msfidelis/serverless-pipeline)!\n\n### Serverless Archictecture Boilerplate with Go? \nLooking for boilerplates to organize big projects using AWS Lambda with Go? [See this repo](https://github.com/msfidelis/serverless-architecture-boilerplate-go)\n\n## Structure \n\n```\n.\n├── modules (modules folder)\n│   └── books (module / context)\n│       ├── endpoints (API endpoints)\n│       │   ├── create.js\n│       │   ├── delete.js\n│       │   ├── read.js\n│       │   └── update.js\n│       └── functions (workers / background functions)\n│           └── worker\n│               └── handler.js\n├── package.json\n├── serverless.yml (serverless config)\n├── handlers (functions config)\n│   ├── books-endpoints.yml (endpoints config)\n│   └── books-workers.yml (workers config)\n├── shared (shared components)\n│   └── lib (shared libraries)\n│       ├── dynamo.js\n│       ├── kinesis.js\n│       ├── lambda.js\n│       ├── parsers.js\n│       ├── sqs.js\n│       └── uuid.js\n└── test (tests folder)\n    └── unit (unit tests folder)\n        ├── modules (unit tests for modules)\n        │   └── books\n        └── shared (unit tests for shared components)\n            └── lib (unit tests for libraries)\n                ├── dynamo.test.js\n                ├── kinesis.test.js\n                ├── parsers.test.js\n                ├── sqs.test.js\n                └── uuid.test.js\n```\n\n## Functions\n\n### HTTP Trigger Function (API Gateway)\n\n```yml\nfunctions:\n\n  # API Endpoints\n  books-register:\n    handler: modules/books/endpoints/create.create #Path to function\n    memorySize: 128 # Lambda Memory Limit\n    timeout: 60 # Lambda Timeout\n    events: \n      - http: # HTTP Trigger \n          path: services/books # API Endpoint\n          method: post # HTTP Method\n\n```\n\n### Cloudwatch Events Functions (Cron)\n\n[Lambda Schedule Docs](https://serverless.com/framework/docs/providers/aws/events/schedule/)\n\n```yml\n# Background Function\n  books-consumer:\n    handler: modules/books/functions/worker/handler.worker #Path to function\n    events:\n      - schedule: #Cloudwatch Event Trigger\n        rate: cron(* * * * * *) # Cron Syntax \n        enabled: true # Trigger Enabled\n\n```\n\n## Development environment \n\nThis boilerplate uses `serverless-local` plugin and some containers and plugins to emulate the AWS Resources\n\n```bash\ndocker-compose up\n```\nThe applications will start on `http://localhost:3000`\n\n### Dev Plugins\n\nThis boilerplate contains following plugins for local development: \n\n* [serverless-offline](https://github.com/dherault/serverless-offline/issues) - For run API Gateway local and manage plugins \n* [serverless-offline-scheduler](https://github.com/ajmath/serverless-offline-scheduler) - CloudWatch Schedule Adapter\n* [serverless-offline-sqs-esmq](https://github.com/msfidelis/serverless-offline-sqs-esmq) - SQS Adapter\n* [serverless-dynamodb-local](https://github.com/99xt/serverless-dynamodb-local/releases) - DynamoDB Adapter\n* [serverless-plugin-split-stacks](https://github.com/dougmoscrop/serverless-plugin-split-stacks) - Split Cloudformation Templates\n\n## Production environment\n\n### Deploy full services\n\n```bash\nserverless deploy -v\n```\n\n[![asciicast](https://asciinema.org/a/4mzSihwWksZvjx7KO6mUy3EmO.png)](https://asciinema.org/a/4mzSihwWksZvjx7KO6mUy3EmO)\n\n\n### Deploy a function \n\n```bash\nserverless deploy function -f books-consumer\n```\n\n### Get function logs\n\n```bash\nserverless books-consumer -f bananinha -t\n```\n\n### Clean All\n\n```bash\nserverless remove\n```\n\n## Testing\n\n**Create Book**\n\n```bash\ncurl -X POST \\\n    -H \"Content-Type: application/json\" \\\n    -d '{\"title\": \"American Gods\", \"author\": \"Neil Gaiman\", \"price\": 10.00  }' \\\n    https://yur25zhqo0.execute-api.us-east-1.amazonaws.com/production/services/books -i\n```\n\n**List Books**\n\n\n```bash\ncurl -X GET \\\n    https://yur25zhqo0.execute-api.us-east-1.amazonaws.com/production/services/books\n```\n\n[![asciicast](https://asciinema.org/a/OAT6cNHhPhfZdgYBSB0sNFN5Q.png)](https://asciinema.org/a/OAT6cNHhPhfZdgYBSB0sNFN5Q)\n\n\n**Detail Book**\n\n```bash\ncurl -X GET \\\n    https://yur25zhqo0.execute-api.us-east-1.amazonaws.com/production/services/books/456c9e8f-6c50-d656-dc69-dc828c42af65\n```\n\n**Delete Book** \n\n```bash\ncurl -X DELETE \\\n    https://yur25zhqo0.execute-api.us-east-1.amazonaws.com/production/services/books/456c9e8f-6c50-d656-dc69-dc828c42af65 -i \n```\n\n**Update Book**\n\n```bash\ncurl -X PUT \\\n    -d '{\"title\": \"updated modafoca\"}' -H \"Content-type: application/json\" \\\n    https://eusrv4mci5.execute-api.us-east-1.amazonaws.com/production/services/books/bbafdb0c-ee6e-fca0-f224-ed534f5b7766 -i\n```\n\n[![asciicast](https://asciinema.org/a/2AbL3Gefn565F2WYJN9f50RlP.png)](https://asciinema.org/a/2AbL3Gefn565F2WYJN9f50RlP)\n\n\n## Custom and Environment Variables\n\n### Custom Items\n\n\u003e Creating and Using custom variables to build dynamic name\n\n```yml\ncustom:\n  region: ${self:provider.region} \n  stage: ${opt:stage, self:provider.stage}\n  prefix: ${self:custom.stage}-${self:service}\n  process: ${self:custom.prefix}-process\n  config: ${self:custom.prefix}-config\n  dynamo-books: ${self:custom.prefix}-BooksCatalog\n  sns-logs: ${self:custom.prefix}-trigger-logs \n  sqs-logs: ${self:custom.prefix}-messages-logs\n```\n\n### Environment Variables\n\n\u003e Building URL Resources using CloudFormation parameters and Custom Variables \n\n```yml\n  environment: # Global Environment variables\n    DYNAMO_TABLE_BOOKS: ${self:custom.dynamo-books} # Reference to Custom Env\n    SQS_QUEUE_URL: 'https://sqs.${self:provider.region}.amazonaws.com/#{AWS::AccountId}/${self:custom.sqs-logs}'\n    REGION: ${self:custom.region}\n```\n\n\n\n## Manage AWS Cloudformation with Serverless\n\n### IAM Roles\n\n[IAM Docs](https://serverless.com/framework/docs/providers/aws/guide/iam/)\n\n```yml\n  iamRoleStatements: # Permissions for all of your functions can be set here\n\n  - Effect: Allow\n    Action: # Gives permission to DynamoDB tables in a specific region\n      - dynamodb:DescribeTable\n      - dynamodb:Query\n      - dynamodb:Scan\n      - dynamodb:GetItem\n      - dynamodb:PutItem\n      - dynamodb:UpdateItem\n      - dynamodb:DeleteItem\n    Resource: \"arn:aws:dynamodb:us-east-1:*:*\"\n\n  - Effect: Allow\n    Action: # Gives permission to Lambda execution\n      - lambda:InvokeFunction\n      - lambda:InvokeAsync\n    Resource: \"*\"\n```\n\n### Manage Infrastructure Components - [Docs](https://serverless.com/framework/docs/providers/aws/guide/resources/#aws-cloudformation-resource-reference)\n\n```yml\n# Infrastrucure - Cloud Formation\nresources:  # CloudFormation template syntax\n\n  Resources:\n    #DynamoDB Books Table\n    BooksCatalog:\n      Type: AWS::DynamoDB::Table # CloudFormation Pseudo Parameter Example\n      Properties:\n        TableName: ${self:custom.dynamo-books}\n        AttributeDefinitions:\n          - AttributeName: hashkey\n            AttributeType: S\n        KeySchema:\n          - AttributeName: hashkey\n            KeyType: HASH\n        ProvisionedThroughput:\n          ReadCapacityUnits: 2\n          WriteCapacityUnits: 1\n\n    # SQS Queue to Update DynamoDB\n    BooksQueueExample:\n      Type: AWS::SQS::Queue\n      Properties:\n        QueueName: ${self:custom.sqs-logs}\n        MessageRetentionPeriod: 1209600\n        VisibilityTimeout: 60\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsfidelis%2Fserverless-architecture-boilerplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsfidelis%2Fserverless-architecture-boilerplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsfidelis%2Fserverless-architecture-boilerplate/lists"}