This package demonstrates how to build, test and deploy an AWS serverless web application.
- node 14+
- docker & docker compose (optional)
yarn install
docker-compose up
open http://localhost:8080
Create a dynamodb table in the local dynamodb instance
aws dynamodb create-table \
--table-name serverless-demo \
--attribute-definitions AttributeName=PK,AttributeType=S AttributeName=SK,AttributeType=S \
--key-schema AttributeName=PK,KeyType=HASH AttributeName=SK,KeyType=RANGE \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
--endpoint-url http://localhost:8000 \
--region local
- packages/frontend - an angular application (could be reactjs, vuejs or an html file)
- packages/backend - contains lambda functions
- packages/cdk - contains cdk application that defines infrastructure
- packages/dev-server - an express server to emulate api gateway with lambda integrations
A docker-compose.yaml file is provided to run the following app containers
cloudfront
a nginx reverse proxy that emulates cloudfront by routing traffic to thefrontend
andbackend
origins on http://localhost:8080. The nginx config file is packages/dev-server/nginx.conffrontend
node container running the angular dev server from packages/frontend in watch mode on http://localhost:4200. This emulates the static site being served from a s3 bucket websitebackend
a node container running an express server for invoking lambdas on http://localhost:3000. This emulates an API gateway that invokes the lambda. The express configuration is at packages/dev-server/dev-server.tsdynamodb
a local instance of aws dynamodb running on http://localhost:8000. This container used a docker volume to persist data between sessions. You can access the table with aws cli using the "--endpoint-url" flag like:aws dynamodb list-tables --endpoint-url https://localhost:8080
- Create the lambda in packages/frontend/src
- Define an express route for lambda in packages/dev-server/dev-server.ts
- Define the Lambda Function in packages/cdk/lib/cdk-stack.ts and create the appropriate api gateway resource/method