Serveless Seed API project using AWS CloudFormation (base values and resources), AWS Systems Manager (for parameters), AWS Lambda (endpoint handlers), Amazon API Gateway (REST and GraphQL enpoints), Amazon Simple Email Service (well, emails), Amazon Cognito (users and auth) and MongoDB (database).
- Easy project and service configuration.
- Logical folder structure.
- Simplified authorization handling.
- Simplified database connection management with Mongoose (MongoDB).
- Simplified HTTP response handling.
- GraphQL lambda endpoint.
- REST endpoint.
- Mailing integration with Amazon Simple Email Service.
Anything can be removed or changed, so if you need to create a service to just handle S3 events, you can just leave a function to handle that. There are no limitations.
- Clone this repo into a folder.
- Update the
"name"
and"title"
properties on thepackage.json
file. These will be used by the CloudFormation template and Serverless to identify the project. - Create an IAM programmatic-only user (recommended) and configure the credentials with the AWS CLI:
aws configure --profile <profile-name>
. - Configure your AWS profile names on
configs/aws.js
for each stage. Must match the profile names configured with the AWS CLI. - Run
npm i
,update
andaudit fix
as needed. - Set the input values to use on the CloudFormation template on
setup/stack/values.js
. - Configure your CloudFormation template on the
setup/stack/template/
folder. - Run
npm run setup
, selectstack
, select the target stage and enter the template values. - Wait for it to finish (it may take a while)...
- Configure your SSM to
.env
values mapping onconfigs/ssm.env.js
with the SSM param names only without path prefixes as defined on yout CloudFormation template. - Run
npm run setup
, selectenv
and select target stage to create or update your local.env.<stage>
file. - Run
npm start
.
That's it. Your App should be running wherever it says it's running.
See the "scripts"
section on the package.json
for more commands.
We decided to use separate stacks to avoid dependencies between the Serverless and base stacks. The base stack may contain references to Cognito or other critical services that should not be deleted when removing the Serverless service or modified on every deploy.
This could be solved with the Serverless Plugin Additional Stacks but we needed an easy way to setup and configure reproductible environments on each stage.
We've bundled some utility scripts that you may find useful while developing or maintaining your app. To run them, user ts-node
like this:
$ ts-node scripts/users/create.ts
You can also run any script defined on the package.json
with npm run list
.
SES email template uploading are handled by the Serverless SES Template plugin.
To edit your templates, open the email/templates/
folder and modify or create as you see fit.
To use a format other than the default with Pug, just modify the loader on configs/ses/templates.js
.
GraphQL is included with Apollo Server Lambda.
See the service/entities/
folder to add or create entities.
Modify the service/configs/graphql.ts
file to change your resolvers (must be added manually).
- Make sure you have the
.env
file for the stage you want to deploy by runningnpm run setup:env
, selecting the target stage and checking if the.env.<stage>
file exists. - Run
npm run deploy
and select stage.
You can also append the --stage <stage>
to the command: npm run deploy -- --stage development
.
To integrate with your CI/CD service just use npm run setup:env -- --stage <stage>
and then npm run deploy -- --stage <stage>
commands. This will pull the env values from SSM and create a .env.<stage>
file that the dotenv
plugin will pick on deploy.
- Create a repo.
- Add remote as slseed:
git remote add slseed [email protected]:fiquu/slseed-web-api.git
- Disable pushing:
git remote set-url --push slseed DISABLED
- Fetch the latest changes:
git fetch slseed
- Merge the master into your branch:
git merge slseed/master --allow-unrelated-histories
Repeat the last 2 steps to update your repo with the latest changes from this one:
git fetch slseed && git merge slseed/master --allow-unrelated-histories
And have fun resolving conflicts!