{"id":15363778,"url":"https://github.com/javieraviles/serverless-aws","last_synced_at":"2025-09-02T11:40:52.768Z","repository":{"id":46061786,"uuid":"260406379","full_name":"javieraviles/serverless-AWS","owner":"javieraviles","description":"Example REST API using the serverless stack from AWS: - Lambda - DynamoDB - SAM - API Gateway","archived":false,"fork":false,"pushed_at":"2021-11-16T22:15:33.000Z","size":18,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T20:26:44.184Z","etag":null,"topics":["api-gateway","aws","aws-dynamodb","aws-lambda","aws-s3","aws-sdk","github-actions","newman","postman","rest-api","sam-cli","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/javieraviles.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":"2020-05-01T07:52:59.000Z","updated_at":"2022-09-21T15:09:39.000Z","dependencies_parsed_at":"2022-08-30T20:10:54.706Z","dependency_job_id":null,"html_url":"https://github.com/javieraviles/serverless-AWS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/javieraviles/serverless-AWS","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javieraviles%2Fserverless-AWS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javieraviles%2Fserverless-AWS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javieraviles%2Fserverless-AWS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javieraviles%2Fserverless-AWS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/javieraviles","download_url":"https://codeload.github.com/javieraviles/serverless-AWS/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javieraviles%2Fserverless-AWS/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266870579,"owners_count":23998250,"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","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["api-gateway","aws","aws-dynamodb","aws-lambda","aws-s3","aws-sdk","github-actions","newman","postman","rest-api","sam-cli","serverless"],"created_at":"2024-10-01T13:08:27.658Z","updated_at":"2025-07-24T16:21:28.873Z","avatar_url":"https://github.com/javieraviles.png","language":"JavaScript","readme":"# serverless-AWS\nExample REST API using the serverless stack from AWS: **Lambda, DynamoDB, SAM, API Gateway**\n\n- [serverless-AWS](#serverless-aws)\n  - [Available endpoints:](#available-endpoints)\n  - [Prerequisites](#prerequisites)\n  - [How to deploy the API](#how-to-deploy-the-api)\n    - [SAM configuration](#sam-configuration)\n    - [SAM deploy](#sam-deploy)\n  - [Short code overview](#short-code-overview)\n    - [dbManager.js](#dbmanagerjs)\n    - [Template.yaml](#templateyaml)\n  - [Entities](#entities)\n    - [Post](#post)\n    - [Comment](#comment)\n  - [Integration Tests](#integration-tests)\n  - [Github Actions pipeline](#github-actions-pipeline)\n\n## Available endpoints:\n| Method | Resource                             |\n| ------ |:------------------------------------:|\n| GET    | /posts                               |\n| GET    | /posts/{postId}                      |\n| POST   | /posts                               |\n| POST   | /posts/{postId}/comments             |\n| PUT    | /posts/{postId}                      |\n| DELETE | /posts/{postId}                      |\n| DELETE | /posts/{postId}/comments/{commentId} |\n\n## Prerequisites\nIn order to deploy this lambda application into you AWS environment, you will first need:\n- AWS account (educate, free tier or normal)\n- [SAM cli installed](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)\n- [AWS credentials configured](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html)\n\n## How to deploy the API\n### SAM configuration\nYou can manually create this file or use the command `sam deploy --guided` to interactively create it.\n\n```\nversion = 0.1\n[default]\n[default.deploy]\n[default.deploy.parameters]\nstack_name = \"serverless-aws\"\ns3_bucket = \"s3.cloudapps.codeurjc\"\ns3_prefix = \"serverless-aws\"\nregion = \"us-east-1\"\ncapabilities = \"CAPABILITY_IAM\"\n```\n\nImportant information here is the **S3 Bucket** where your code will get packaged to and it's prefix. Also the **region** in where your API will get deployed, and where your DynamoDB is, please notice lines 4 to 6 in `src/dbManager.js`:\n\n```\nAWS.config.update({\n    endpoint: \"https://dynamodb.us-east-1.amazonaws.com\"\n});\n```\n### SAM deploy\nOnce `samconfig.toml` is in place, you can already perform `sam deploy` and your lambda application sould get deployed in your AWS account. Thanks to the last line of the file `template.yaml`, the logs from deploy should at the very end print the prod url where the API is now available:\n\n```\nValue: !Sub \"https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/posts/\"\n```\n\nOnce deployed, feel free to use the provided **Postman** collection against the API.\n\n## Short code overview\nThe key parts are `src/dbManager.js` and `template.yaml`.\n### dbManager.js\nThis file first imports the node AWS sdk `const AWS = require('aws-sdk')` and creates a Dynamo DocumentClient `const docClient = new AWS.DynamoDB.DocumentClient()` to manage documents against the database on each lambda. Now retrieving a collection from a lambda would be as easy as:\n\n```\nconst params = {\n    TableName: 'posts'\n};\n\nreturn docClient.scan(params).promise();\n```\n\nA more complex example would be creating a comment within a Post comments collection: \n```\nconst params = {\n    TableName: 'posts',\n    Key: {\n        \"postid\": postid\n    },\n    UpdateExpression: 'set comments.#commentid = :comment',\n    ExpressionAttributeNames: {\n        \"#commentid\": commentid\n    },\n    ExpressionAttributeValues: {\n        \":comment\": comment,\n    },\n    ReturnValues: \"UPDATED_NEW\"\n};\nreturn docClient.update(params).promise();\n```\n\nNotice as well the parameter `Returnalues` where what the API will return after the action is carried out\n\n### Template.yaml\nDefines a lambda function defining the events that will trigger this function, such as this piece of code:\n```\nlambdaGetPost:\n  Type: Api\n  Properties:\n      Path: /posts/{postid}\n      Method: GET\n```\nWill make a GET to the resource `/posts/{postid}` trigger our lambda application.\n\nThis template also defines one or more policies that this function needs. They will be appended to the default role for this function. This way:\n```\nEffect: Allow\nAction:\n    -   'dynamodb:Scan'\n    -   'dynamodb:Query'\n    -   'dynamodb:DeleteItem'\n    -   'dynamodb:GetItem'\n    -   'dynamodb:PutItem'\n    -   'dynamodb:UpdateItem'\n```\n\nAll these actions will be allowed over DynamoDB.\n\nThe second part of the yaml file, defines a **DynamoDB** table:\n```\nType: 'AWS::DynamoDB::Table'\nProperties:\n    TableName: posts\n    AttributeDefinitions:\n        -   AttributeName: postid\n            AttributeType: S\n    KeySchema:\n        -   AttributeName: postid\n            KeyType: HASH\n    ProvisionedThroughput:\n        ReadCapacityUnits: 5\n        WriteCapacityUnits: 5\n```\n\n## Entities\n### Post\n```\n{\n\t\"name\": \"Jack Nicholson\",\n\t\"nickname\": \"Nicky\",\n\t\"title\": \"My Joker was good too\",\n\t\"content\": \"Respect for Heath Ledger and Joaquin Phoenix\",\n\t\"comments\": {}\n}\n```\n\n### Comment\n```\n{\n\t\"nickname\": \"Random Internet Guy\",\n\t\"comment\": \"Here is Johnny!\",\n\t\"creationDate\": \"2019-11-26 10:15:55\"\n}\n```\n\n## Integration Tests\nFind inside directory `src/integrationtests` a straightforward postman collection, including test assertions, testing every endpoint and a main application flow:\n1. Create a Post\n2. Get all available Posts\n3. Get a specific Post checking structure\n4. Modify the Post's nickname\n5. Get it again to check whether it was modified correctly\n6. Add a Comment to the Post\n7. Delete the Comment\n8. Delete the Post\n\nTo run them, you have basically two options:\n- Import the collection in Postman and run them manually\n- Install Newman `npm install -g newman` and execute `npm run test:integration`\n\n## Github Actions pipeline\nA very simple actions pipeline is provided in this project too. The file `.github/workflows/ci.yml` will create a pipeline which will trigger the postman collection automatically using newman against the production url for the api:\n```\nintegration_tests:\n    name: Run integration tests\n    runs-on: ubuntu-16.04\n    steps:\n    - uses: actions/checkout@master\n    - uses: actions/setup-node@v1\n      with:\n        node-version: '12.x'\n    - name: Install Newman\n      run: npm install -g newman\n    - name: Integration Tests\n      run: cd src \u0026\u0026 npm run test:integration\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavieraviles%2Fserverless-aws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjavieraviles%2Fserverless-aws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavieraviles%2Fserverless-aws/lists"}