The NestJS + Sequelize sample application is a REST API for managing users built using the NestJS web framework and Sequelize ORM.
This guide assumes:
@klotho::expose
@klotho::persist
POST /users
- Creates a new user in the database from the data supplied in the request body.GET /users
- Gets all registered users from the database.GET /users/:id
- Gets the user associated with the suppliedid
path parameter from the database. This application uses Nest'sExpressAdapter
to take advantage of Klotho's existing support for Express.
npm install
npm run start
# unit tests
npm run test
# e2e tests
npm run test:e2e
# test coverage
npm run test:cov
run the terminal commands:
# Compile the app
npx tsc && klotho . --app ts-nestjs-sequelize -p aws
# Go into the compiled directory
cd compiled
# If you didn't set the aws region as indicated in the compiler output, do that now
pulumi config set aws:region <YOUR_REGION> -s ts-nestjs-sequelize
# Set a username and password to be used for accessing `UsersDB`
pulumi config set ts-nestjs-sequelize:usersdb_username <USERNAME> -s ts-nestjs-sequelize
pulumi config set --secret ts-nestjs-sequelize:usersdb_password <PASSWORD> -s ts-nestjs-sequelize
# npm install pulumi dependencies
npm install
# Deploy
pulumi up -s ts-nestjs-sequelize
# Outputs: {
# apiUrl: 'https://<...>.execute-api.<YOUR_REGION>.amazonaws.com/stage/'
# }
curl --request POST 'https://<...>.execute-api.<YOUR_REGION>.amazonaws.com/stage/users' \
--header 'Content-Type: application/json' \
--data-raw '{ "id": 1, "firstName": "John", "lastName": "Doe" }'
# status code: 201
curl https://<...>.execute-api.<YOUR_REGION>.amazonaws.com/stage/users/<ID>
{
"id": 1,
"firstName": "John",
"lastName": "Doe"
}
curl https://<...>.execute-api.<YOUR_REGION>.amazonaws.com/stage/users
[
{
"id": 1,
"firstName": "John",
"lastName": "Doe"
}
]
From the compiled directory still,
# Tear down when done
pulumi destroy -s ts-nestjs-sequelize