This project is template for serverless compose using typescript.
Some personal modifications are:
- Git hooks with Husky, running ESLint, Prettier and Tests on every commit.
- Open API documentation with redoc-cli.
- Packaging using esbuild serverless-esbuild
- Publish ssm with reference from stack resourcesserverless-ssm-publish
- Prune of Old Lambda Versions with serverless-prune-plugin.
- Run
yarnto install the project dependencies - Run
yarn sls deployto deploy this stack to AWS
This template contains 2 services stack with a single lambda function in each stack triggered by an HTTP request made on the provisioned API Gateway REST API /hello route with GET method.
- requesting any other path than
/hellowith any other method thanGETwill result in API Gateway returning a403HTTP error code - sending a
GETrequest to/hellowill result in API Gateway returning a200HTTP status code with a message saluting the provided name and the detailed event processed by the lambda
⚠️ As is, this template, once deployed, opens a public endpoint within your AWS account resources. Anybody with the URL can actively execute the API Gateway endpoint and the corresponding lambda. You should protect this endpoint with the authentication method of your choice.
Copy and replace your url - found in Serverless deploy command output - and name parameter in the following curl command in your terminal or in Postman to test your newly deployed application.
curl --location --request GET 'https://myApiEndpoint/dev/hello' \
--header 'Content-Type: application/json'
It uses serverless-ssm-publish package, which publishes current environment name to SSM as a example. You can publish any kind of refs to ARN or resources name to SSM after deployment and use those SSM in your code.
Other feature is you can output variables from one stack to another and use it using ${param:name_of_outputed_param}
The project code base is mainly located within the src folder. This folder is divided in:
functions- containing code base and configuration for your lambda functionslibs- containing shared code base between your lambdas
.
├──serviceA
│ ├── src
│ │ ├── functions # Lambda configuration and source code folder
│ │ │ ├── hello
│ │ │ │ ├── handler.ts # `Hello` lambda source code
│ │ │ │ ├── index.ts # `Hello` lambda Serverless configuration
│ │ │ │ ├── mock.json # `Hello` lambda input parameter, if any, for local invocation
│ │ │ │ └── schema.ts # `Hello` lambda input event JSON-Schema
│ │ │ │
│ │ │ └── index.ts # Import/export of all lambda configurations
│ │ │
│ │ └── libs # Lambda shared code
│ │ └── apiGateway.ts # API Gateway specific helpers
│ │
│ ├── package.json
│ ├── serverless.ts # Serverless service file
│ └── tsconfig.json # Typescript compiler configuration
├──serviceB
│
├──serverless-compose.ts
├──package.json
├──yarn.lock
├──docs
│
- json-schema-to-ts - uses JSON-Schema definitions used by API Gateway for HTTP request validation to statically generate TypeScript types in your lambda's handler code base
- middy - middleware engine for Node.Js lambda. This template uses http-json-body-parser to convert API Gateway
event.bodyproperty, originally passed as a stringified JSON, to its corresponding parsed object - @serverless/typescript - provides up-to-date TypeScript definitions for your
serverless.tsservice file - redoc-cli - provides a tool to configure and write our documentation using OpenAPI Specification.
- serverless-prune-plugin - prunes old lambda versions.
- serverless-ssm-publish - Publish custom data to AWS SSM Parameter Store from serverless.yaml or Cloud Formation Output
- serverless-esbuild - Serverless Framework plugin for zero-config JavaScript and TypeScript code bundling using promising fast & furious esbuild bundler and minifier