lambda-typescript-skeleton
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Project boilerplate

This skeleton contains a basic Amazon Web Services (AWS) lambda function written in Typescript with tests, linting and deployment configuration using AWS Serverless Application Model (SAM).

Reasoning

Typescript provides type safety and another layer of protection to capture common errors before code deploy.

You will also get a ton of information from public library which makes it nice to develop with.

Example below:

tooltip

Conventions

This project uses a couple of conventions which simplify running parralel environments and configuration.

Environment

The project has a couple of parameters which are used as a label for resources created, it is composed of:

  • EnvironmentName: The name or identifier used for the environment. eg dev, stage or prod
  • EnvironmentNumber: This is typically a sequence number given to different sub environments.

Configuration

Systems Manager Parameter Store as secret and configuration storage system. To retrieve configuration items we have provisioned prior to launch of a stack we use the EnvironmentName and EnvironmentNumber to compose a key and retrieve a given setting. An example of his is seen below where the EnvironmentName is dev, and the EnvironmentNumber is one.

/dev/1/DB_URI

This enables storage of any number of configuration parameters.

Prerequisites

Install NodeJS.

brew install node

Install Typescript.

npm install typescript -g

Install Typescript Lint.

npm install tslint

Install the aws CLI.

brew install awscli

Note: This setup assumes mac, it is just here to illustrate the requirements and give you the gist of what is needed.

Setup

This project is designed as a template for your project, just clone it then start developing in your favourite editor.

Then remove the git directory, and setup your new git project.

cd your-project-name
rm -rf .git
git init
git add .
git commit -a "Initial import of skeleton project"

Usage

Run the tests.

make test

To run a local test event:

make local ev=events/postuser.json fn=Authenticator
make local ev=events/deleteuser.json fn=Authenticator

To deploy the skeleton, you will need to specify a ENV and ENV_NO.

ENV=dev ENV_NO=2 make

Deploy the skeleton, this will use the S3_BUCKET to stage the handler.zip file, prior to deployment with SAM.

S3_BUCKET=somebucket.example.com make

More examples are documented in the Makefile

Note: The Makefile has been built to enable reproducible builds, this should mean deployments only happen when the code or dependencies are updated.

License

This project is released under The Unlicense, your free to copy this and do what you like.

Readme

Keywords

none

Package Sidebar

Install

npm i lambda-typescript-skeleton

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

282 kB

Total Files

33

Last publish

Collaborators

  • richdot