aws-blueprint REST API example using AWS SAM and NestJS
MIT License
aws-blueprint example for a NestJS based API using AWS Serverless Application Module (SAM).
Features:
sam local
).sam local start-api
. Talks to DynamoDB local via docker-compose.admin:repo_hook, public_repo, repo:status, repo_deployment
.cp dotenv.example .env
make dynamo/init
will load local DynamoDB with sample data (dropping table if exists).yarn install
make run/local-dev-server
will start server locally, and hot-reload on changes.ENV_TEST
is undefined? Keep reading...This repo utlizes sam local start-api
cli to simulate APIG->Lambda->NestJS.
Enviornment variables are pulled from sam-template.yml::Environment.Variables
(not .env
). To simulate how these will be set in cloudformation, the --parameter-overrides
sam
option is used. See run/sam-start-api
in Makefile for an example.
make run/watch
will compile typescript on file changes.make run/sam-start-api
Startup is slow right? This simulates Lambda cold starts. See here.
The parameter SomeSecretInSSM
in sam-template.yml dictates where in SSM to pull a value, which is then set as an env var in the lambda (see SECRET_KEY
in sam-template.yml). In CodePipeline you set the SomeSecretInSSM
param value on a stage-by-stage basis aws/cloudformation/parameters. In test-pipeline-parameters.json you'll notice it is set to /test/abp-sam-nestjs/master/envs/SECRET_KEY
. If you update the value in SSM, just execute a stack update to get the new env var into lambda.
/test/abp-sam-nestjs/master/envs/SECRET_KEY
with any value you like.abp-sam-nestjs--master--api--cicd
(naming convention is [gitrepo]--[branch]--[eyecatcher]--cicd
)git push
and watch the pipeline. Will need to approve to promote to next stage. URL to your API is in the outputs
of the ExecuteChangeSet
CloudFormation.