This project was bootstrapped with Create Serverless Stack.
- Rokket Labs code configuration
- Serverless Stack (SST)
- Cognito Authentication (with post confirmation handlers and custom email templates)
- S3 Bucket configuration and permissions
- Apollo GraphQL with Code First approach (TypeGraphQL)
- MongoDB with Typegoose
- RBAC Authorization examples
- Pagination model examples
- [] Jest test environment
Start by installing the dependencies.
$ yarn
Starts the local Lambda development environment.
Build your app and synthesize your stacks.
Generates a .build/
directory with the compiled files and a .build/cdk.out/
directory with the synthesized CloudFormation stacks.
Deploy all your stacks to AWS. Or optionally deploy a specific stack.
Remove all your stacks and all of their resources from AWS. Or optionally remove a specific stack.
Runs your tests using Jest. Takes all the Jest CLI options.
-
Make sure you set the app name on
sst.json
as this will be used to create every AWS resource name as a prefix. -
Don't update (or add)
@aws-cdk
or@serverless-stack
dependencies manually, as they depend on each others' versions. To update SST, always useyarn sst update <version>
which will take care of all AWS CDK dependencies as well. If you need to add a new AWS CDK package, useyarn sst add-cdk @aws-cdk/<package>
. -
If you need to connect your API to a different Cognito User Pool, add the following environment variables to your setup with their respective IDs:
COGNITO_USER_POOL
andCOGNITO_USER_POOL_CLIENT
. -
Make sure every entrypoint for your stack (every function called either by API Gateway or through an external trigger) includes
import 'reflect-metadata'
at the top of your file, since this app relies heavily on the use of decorators. -
A generic class with pagination options is included on
src/utils/schemas/PaginatedModel.ts
. In order to use this, create a new class that extends from this model and make sure you include thedocs
property, which should be an array of your specific model. -
By default, all endpoints are protected by Cognito JWT authentication. If there's a need for a public GraphQL endpoint, either create a second function which has no auth included, or move authentication to the
src/utils/authChecker.ts
file. Authentication is not necessary for local development, but it is enforced once functions are deployed. -
Cognito emails (account verification, forgot password, etc.) are sent through Cognito itself, which is NOT the best idea for production environments. If you're deploying on a production environment, make sure you follow instructions on
stacks/AuthStack.ts
for configuring an email address and SES configuration for that specific account. -
All entrypoint files (functions) should be set on
src/functions
. -
Make sure you have AWS credentials set on your local computer. They should be on
~/.aws/credentials
, under thedefault
selector. If you have more than one profile on your computer, runexport AWS_PROFILE=<your-profile-name>
before running any commands on this repository.
Learn more about the Serverless Stack.