1 | # <a href="https://faastjs.org"><img alt="faast.js" src="./website/static/img/faastjs.png" height="50"></a>
|
2 |
|
3 | [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) [![CircleCI](https://circleci.com/gh/faastjs/faast.js.svg?style=shield&circle-token=c97f196a78c7173d6ca4e5fc9f09c2cba4ab0647)](https://circleci.com/gh/faastjs/faast.js) [![codecov](https://codecov.io/gh/faastjs/faast.js/branch/master/graph/badge.svg?token=Ml90RLLbEh)](https://codecov.io/gh/faastjs/faast.js) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Ffaastjs%2Ffaast.js.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Ffaastjs%2Ffaast.js?ref=badge_shield)
|
4 |
|
5 | Faast.js makes regular functions callable as serverless functions on AWS Lambda. It handles the details of uploading your code, creating cloud infrastructure, and cleaning up. Scale up your functions to a thousand cores in seconds :rocket:
|
6 |
|
7 | Faast.js is a pure library with no service dependencies, operational overhead, or unnecessary complexity.
|
8 |
|
9 | ## Installation
|
10 |
|
11 | Faast.js requires node version 8+.
|
12 |
|
13 | ```shell
|
14 | $ npm install faastjs
|
15 | ```
|
16 |
|
17 | ## Example
|
18 |
|
19 | First write the functions you want to run in a serverless function. Make sure to export them:
|
20 |
|
21 | ```typescript
|
22 | // functions.ts
|
23 | export function hello(name: string) {
|
24 | return "hello " + name;
|
25 | }
|
26 | ```
|
27 |
|
28 | Use faast.js to turn this into a serverless function:
|
29 |
|
30 | ```typescript
|
31 | // main.ts
|
32 | import { faast } from "faastjs";
|
33 | import * as funcs from "./functions";
|
34 |
|
35 | (async () => {
|
36 | const m = await faast("aws", funcs);
|
37 | const { hello } = m.functions;
|
38 | const result = await hello("world!");
|
39 | console.log(result);
|
40 | await m.cleanup();
|
41 | })();
|
42 | ```
|
43 |
|
44 | Make 1000 concurrent calls if you like:
|
45 |
|
46 | ```typescript
|
47 | const promises: string[] = [];
|
48 | for (let i = 0; i < 1000; i++) {
|
49 | promises.push(hello(`world ${i}!`));
|
50 | }
|
51 | await Promise.all(promises);
|
52 | ```
|
53 |
|
54 | How much did that cost...?
|
55 |
|
56 | ```typescript
|
57 | const cost = await m.costSnapshot();
|
58 | console.log(`$${cost.total()}`);
|
59 | ```
|
60 |
|
61 | Relax. It's just half a penny:
|
62 |
|
63 | ```
|
64 | $0.00420858
|
65 | ```
|
66 |
|
67 | ## Features
|
68 |
|
69 | - **Frictionless.** Faast.js takes care of packaging your code, setting up IAM roles, and other infrastructure complexity. Run your code on a thousand cores in seconds. All you need is an AWS account.
|
70 | - **Scalable.** Use serverless functions to scale your batch jobs up to thousands of cores.
|
71 | - **Cost-effective.** Understand and optimize your workload costs in real time. Pay only for compute time actually used.
|
72 | - **Ephemeral.** No clusters or services to manage. Faast.js creates the infrastructure it uses on the fly and cleans up when it's done.
|
73 | - **Productive.** First class support for TypeScript and JavaScript. Type safety, documentation, and extensive testing are part of our DNA.
|
74 | - **Local.** Built-in support for AWS Lambda and local processing mode when you don't have network access. Switch with one line of code.
|
75 |
|
76 | ## Ready to learn more?
|
77 |
|
78 | Check out our [getting started documentation](https://faastjs.org/docs/introduction).
|
79 |
|
80 | Work through some [examples](https://github.com/faastjs/examples)
|
81 |
|
82 | Review the detailed [API documentation](https://faastjs.org/docs/api/faastjs).
|
83 |
|
84 | Join our [discord channel](https://discord.gg/F3aqjb3).
|
85 |
|
86 | Follow us on [twitter](https://twitter.com/faastjs).
|
87 |
|
88 | ## Contributing
|
89 |
|
90 | See [contributing](./docs/12-contributing.md).
|