Implements a Books API for a Library, intended to be run on AWS using serverless.
- Functions run on AWS Lambda
- Data is stored in AWS DynamoDB
- Uses domain driven design techniques with handlers/utilities/adapters layers
- Correctly configured serverless cli installation
- AWS account with the required priveledges
Parameter | Type | Notes |
---|---|---|
uuid | string | |
name | string | |
releaseDate | integer | timestamp |
authorName | string |
.
├── README.md - Documentation
├── lib
│ ├── adapters - I/O operations
│ ├── functions - Functions that get deployed as lambdas to cloud infrastructure
│ ├── schemas - Used by cloud infrastructure to validate request data
│ └── utils - Shared utility functions
├── serverless.yml - Cloud deployment configuration
├── TODO.md - Task list used to build the project
└── test - Tests
To run the functions locally:
npm install
npm start
The list of the available endpoints will be printed to the console:
POST | http://localhost:3000/dev/book/add
POST | http://localhost:3000/dev/book/{bookUuid}/delete
GET | http://localhost:3000/dev/book/{bookUuid}
GET | http://localhost:3000/dev/books
POST | http://localhost:3000/dev/book/{bookUuid}/update
Ensure you have configured serverless with the correct aws access rights.
Then run:
serverless deploy
Create a test env config file:
echo "export API_BASE_URL=[ADD YOUR BASE URL HERE]" > .env
To run both unit and integration tests:
npm test
Update API_BASE_URL to run the integration tests against different versions of the code (i.e. local / dev / production etc).
You can run individual test sets like so:
npm run test:unit
npm run test:integration
For interactive debugging in VSCode:
- Create a VSCode run config in your project root (.vscode/launch.json) - see sample
- Set some breakpoints in the code or tests files
- Click the Run button
- Select a run configuration from the drop down menu
- Click the play button next to the drop down menu
- The debugger will then run the code and stop at the first breakpoint you set
For additional logging set the following environment variable:
DEBUG=booksapi:*
See the TODO page.
- A way to run both integration tests and lambda code in the debugger at the same time
- Add an authorize function on routes that modify data
I found the following resources helpfull while building this repo:
- AWS SDK for JavaScript
- Serverless Framework Documentation
- Full Stack Developmnt on AWS using Serverless
- Testing Node serverless applications — AWS Lambda functions
- Debugging lambda functions locally in vscode with actual break-points
- DynamoDB Guide
- Serverless Offline
- AWS mocks for Javascript/Node.js aws-sdk
- JSON Schema Validation: A Vocabulary for Structural Validation of JSON