- TypeScript
- AWS Lambda
- AWS DynamoDB
- AWS Cognito User Pool
- Serverless Framework
- Docker for Local DynamoDB
- Code Style with Prettier
- Git Hooks with Husky
- ESLint
Set the correct node version for the project according to the .nvmrc
file
and install node dependencies:
nvm use
npm install
Make sure you have Serverless Framework v3 installed:
serverless -v
# Install it if necessary
npm install -g serverless
After installation, you can start local Serverless emulation with:
npm run local
DynamoDB will run on Docker and the local API Gateway will be available at http://localhost:3000
The Serverless Framework will compile and package the source code and then use your AWS credentials to create the infrastructure on AWS:
npm run deploy
# or
serverless deploy
After deploying, you should see output similar to:
Deploying aws-node-serverless to stage dev (sa-east-1)
✔ Service deployed to stack aws-node-serverless-dev (193s)
endpoints:
GET - https://xxxxxxxxx.execute-api.sa-east-1.amazonaws.com/
POST - https://xxxxxxxxx.execute-api.sa-east-1.amazonaws.com/api/v1/customers
GET - https://xxxxxxxxx.execute-api.sa-east-1.amazonaws.com/api/v1/customers
DELETE - https://xxxxxxxxx.execute-api.sa-east-1.amazonaws.com/api/v1/customers/{email}
functions:
api: aws-node-serverless-dev-api (16 MB)
createCustomer: aws-node-serverless-dev-createCustomer (16 MB)
getCustomers: aws-node-serverless-dev-getCustomers (16 MB)
deleteCustomer: aws-node-serverless-dev-deleteCustomer (16 MB)
Serverless Framework uses AWS Cloud Formation under the hood to create the serverless infrastructure, you can view Cloud Formation Stacks from your AWS account.
After successful deployment, you can call the created application via HTTP:
curl https://xxxxxxxxx.execute-api.sa-east-1.amazonaws.com/api/v1/customers
Which should result in response similar to the following:
{
"total": 0,
"items": []
}
Api Doc
aws-node-serverless.postman_collection.json
With Serverless Framework you can not only quickly create infrastructure on AWS, but you can also delete all created resources if you decide to save costs in the cloud:
npm run destroy
# or
serverless remove
After removing the infrastructure, you should see output similar to:
> aws-node-serverless@1.0.0 destroy
> serverless remove
Removing aws-node-serverless from stage dev (sa-east-1)
✔ Service aws-node-serverless has been successfully removed (36s)