This template demonstrates how to make a simple HTTP API with Node.js and Typescript running on AWS Lambda and API Gateway using the Serverless Framework v3.
This template does not include any kind of persistence (database). For more advanced examples, check out the serverless/examples repository which includes Typescript, Mongo, DynamoDB and other examples.
Run this command to initialize a new project in a new working directory. Ensure you have the Serverless Framework installed and you are using Node.js v20.
nvm install 20
nvm use 20
npm i
serverless deploy -- verbose --aws-profile [aws-profile-name]
Invoke functions locally.
serverless invoke local --function hello
serverless invoke local --function starwars-films-get
serverless invoke local --function starwars-people-get
serverless invoke local --function task-post --data '{"body": "{\"title\":\"YourTitle\",\"description\":\"YourDescription\",\"done\":false}"}' --aws-profile [aws-profile-name]
serverless invoke local --function task-get --aws-profile [aws-profile-name]
You can run the tests locally by running npm test
.
npm test
[GET] https://r2yj9u8c1e.execute-api.us-east-1.amazonaws.com/
[GET] https://r2yj9u8c1e.execute-api.us-east-1.amazonaws.com/starwars-films
[GET] https://r2yj9u8c1e.execute-api.us-east-1.amazonaws.com/starwars-people
[POST] https://r2yj9u8c1e.execute-api.us-east-1.amazonaws.com/task --data '{"title":"YourTitle","description":"YourDescription","done":false}'
[GET] https://r2yj9u8c1e.execute-api.us-east-1.amazonaws.com/task