A simple API that performs Create, Read, Update, and Delete against a table in MongoDB. Includes linting, GitHub Actions workflow, project structuring, and tests. This repository was created as part of an extended example for the book Building Node.js serverless apps on AWS: A Brief Guide on Where to Start. This project does not contain any auth setup like the Serverless AWS Starter Project.
Have serverless installed locally and on your CI/CD pipeline:
npm install -g serverless
Make sure that you have your AWS Key and Secret in your env vars or bash profile:
export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY_ID"
export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_ACCESS_KEY"
To deploy to AWS locally, make sure you have your AWS key and secret in your bash profile and execute the following:
sls deploy -v --stage <dev, test, staging, production, etc>
To execute locally, run the following command (npm install serverless -g is required):
sls offline
or
npm start
If running locally, the beginning of your url will be http://localhost:3000
A sample Postman collection has been provided in the misc folder.
The Dockerfile in the repository uses an official Node image from Docker. To build the docker image with your project, run the following command:
docker build -t bookapi -f Dockerfile .
Then, to run the app along with a mongo container, run the following:
docker-compose up
The base image is the official node image: node 12.22.1-alpine
If you'd like to build your own, its the following definition:
FROM node:12.22.1-alpine3.12
# Install global dependencies
RUN npm install serverless -g
RUN npm install serverless-offline -g