<commit_before>---
title: "Serverless Framework with TypeScript and AWS: Getting Started"
date: 2017-12-10T18:08:22-05:00
languages: ["TypeScript"]
# tools: []
techniques: [ "Serverless Architecture" ]
frameworks: [ "Serverless Framework" ]
projects: [ "Form2Email" ]
draft: false
---
# Serverless and TypeScript

<img alt="Serverless Framework logo" src="/img/serverless-framework-logo_150x150.png" style="float: right; padding:8px" /> [Serverless Framework](https://serverless.com/), or simply "Serverless", is an excellent provider-agnostic framework for defining the **functions** and **events** that make up your service. Once defined your events and functions are defined, Serverless deploys your service to the target cloud provider by automatically provisioning the required infrastructure and deploying the application to it.

While getting started, I found that most [Serverless Framework examples](http://www.jamestharpe.com/frameworks/serverless-framework/) are in JavaScript. However, I prefer the strong-typing and smarter tooling of TypeScript so I made it my mission to write a simple Serverless microservice using Serverless and TypeScript.

In this article, I'll explain how to scaffold a Serverless Framework service with TypeScript and unit tests (using Mocha). In a later article, I'll actually code something useful.

## Starting a Serverless TypeScript Project

To get started, install Serverless and create a new project using TypeScript targeted at AWS:

```bash
npm install -g serverless
```

Next, create a new project using the `aws-nodejs-typescript` template:

```bash
$ serverless create --template aws-nodejs-typescript && npm install
Serverless: Generating boilerplate...
 _______                             __
|   _   .-----.----.--.--.-----.----|  .-----.-----.-----.<commit_msg>Adds Mocha, Chai frameworks<commit_after>---
title: "Serverless Framework with TypeScript and AWS: Getting Started"
date: 2017-12-10T18:08:22-05:00
languages: ["TypeScript"]
# tools: []
techniques: [ "Serverless Architecture" ]
frameworks: [ "Serverless Framework", "Mocha", "Chai" ]
projects: [ "Form2Email" ]
draft: false
---
# Serverless and TypeScript

<img alt="Serverless Framework logo" src="/img/serverless-framework-logo_150x150.png" style="float: right; padding:8px" /> [Serverless Framework](https://serverless.com/), or simply "Serverless", is an excellent provider-agnostic framework for defining the **functions** and **events** that make up your service. Once defined your events and functions are defined, Serverless deploys your service to the target cloud provider by automatically provisioning the required infrastructure and deploying the application to it.

While getting started, I found that most [Serverless Framework examples](http://www.jamestharpe.com/frameworks/serverless-framework/) are in JavaScript. However, I prefer the strong-typing and smarter tooling of TypeScript so I made it my mission to write a simple Serverless microservice using Serverless and TypeScript.

In this article, I'll explain how to scaffold a Serverless Framework service with TypeScript and unit tests (using Mocha). In a later article, I'll actually code something useful.

## Starting a Serverless TypeScript Project

To get started, install Serverless and create a new project using TypeScript targeted at AWS:

```bash
npm install -g serverless
```

Next, create a new project using the `aws-nodejs-typescript` template:

```bash
$ serverless create --template aws-nodejs-typescript && npm install
Serverless: Generating boilerplate...
 _______                             __
|   _   .-----.----.--.--.-----.----|  .-----.-----.-----.
{'fraction_non_alphanumeric': 0.10953291450423382, 'fraction_numerical': 0.014203769461895657, 'mean_word_length': 4.172316384180791, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6712658', 'n_tokens_mistral': 1022, 'n_tokens_neox': 936, 'n_words': 399}