How to use faastjs - 10 common examples

To help you get started, we’ve selected a few faastjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github faastjs / faast.js / examples / map-buckets.ts View on Github external
export async function mapBucket(Bucket: string, keyFilter: (key: string) => boolean) {
    const faastModule = await faast("aws", m, {
        memorySize: 2048,
        timeout: 300,
        mode: "queue",
        concurrency: 2000,
        childProcess: true,
        gc: "off"
        // awsLambdaOptions: { TracingConfig: { Mode: "Active" } }
    });
    console.log(`Logs: ${faastModule.logUrl()} `);
    faastModule.on("stats", s => {
        console.log(`${s}`);
    });

    const bandwidth = new Statistics();

    try {
github faastjs / faast.js / examples / cost-estimate.ts View on Github external
(async () => {
    const m = await faast("aws", funcs);
    await m.functions.hello("world");
    const cost = await m.costSnapshot();
    console.log(`hello world cost: $${cost.total()}`);
    // hello world cost: $0.0000030596957398557663
    await m.cleanup();
})();
github faastjs / examples / aws-puppeteer-ts / index.ts View on Github external
async function main() {
    const m = await faastAws(funcs, {
        memorySize: 1728,
        awsLambdaOptions: {
            // chrome-aws-lambda only works with node8.10 for now.
            Runtime: "nodejs8.10"
        },
        packageJson: {
            dependencies: {
                "chrome-aws-lambda": "latest",
                "puppeteer-core": "latest"
            }
        }
    });
    try {
        const rv = await m.functions.runPuppeteer("https://example.com");
        console.log(rv.title);
        writeFileSync("output.png", rv.screenshot);
github faastjs / faast.js / examples / map-buckets.ts View on Github external
export async function mapBucket(Bucket: string, keyFilter: (key: string) => boolean) {
    const faastModule = await faast("aws", m, {
        memorySize: 2048,
        timeout: 300,
        mode: "queue",
        concurrency: 2000,
        childProcess: true,
        gc: "off"
        // awsLambdaOptions: { TracingConfig: { Mode: "Active" } }
    });
    console.log(`Logs: ${faastModule.logUrl()} `);
    faastModule.on("stats", s => {
        console.log(`${s}`);
    });

    const bandwidth = new Statistics();

    try {
        let allObjects = await listAllObjects(Bucket);
        allObjects = allObjects.filter(obj => keyFilter(obj.Key!));
        const promises = [];
        console.log(`Bucket ${Bucket} contains ${allObjects.length} matching objects`);
        const start = Date.now();
        for (const Obj of allObjects) {
            promises.push(
                faastModule.functions
                    .processBucketObject(Bucket, Obj.Key!)
                    .catch((err: FaastError) => {
                        console.log(`Error processing ${Obj.Key!}`);
                        console.log(`Logs: ${err.logUrl}`);
                    })
            );
github teppeis / duck / src / batch.ts View on Github external
CommonOptions,
  faastAws,
  faastLocal,
  FaastModuleProxy,
  LocalOptions,
  log,
} from "faastjs";
import mergeOptions from "merge-options";
import semver from "semver";
import { assertNonNullable } from "./assert";
import * as compilerFaastFunctions from "./compiler-core";
import { DuckConfig } from "./duckconfig";
import { logger } from "./logger";

// change to stdout
log.info.log = console.log.bind(console);

export async function getFaastCompiler(
  config: DuckConfig
): Promise> {
  logger.info("Initializing batch mode");
  const batch = assertNonNullable(config.batch);
  const batchOptions = getBatchOptions(config);
  const m =
    batch === "aws"
      ? await faastAws(compilerFaastFunctions, batchOptions as AwsOptions)
      : batch === "local"
      ? await faastLocal(compilerFaastFunctions, batchOptions as LocalOptions)
      : null;
  if (!m) {
    throw new TypeError(`Unsupported batch mode: ${batch}`);
  }
github faastjs / faast.js / examples / invoke-1000.ts View on Github external
(async () => {
    const m = await faast("aws", funcs);
    const promises = [];
    // Summon 1000 cores
    for (let i = 0; i < 1000; i++) {
        promises.push(m.functions.hello("world " + i));
    }
    await Promise.all(promises);
    await m.cleanup();
})();
github faastjs / examples / aws-sharp-ts / index.ts View on Github external
async function main() {
    const m = await faast("aws", funcs, {
        packageJson: {
            dependencies: {
                sharp: "latest"
            }
        }
    });
    try {
        const rv = await m.functions.runSharp();
        writeFileSync("output.png", rv);
        console.log(`wrote output.png`);
    } finally {
        await m.cleanup();
    }
}
github faastjs / examples / hello-world-js / index.js View on Github external
async function main() {
    const m = await faast("local", funcs);
    try {
        const result = await m.functions.hello("world");
        console.log(result);
    } finally {
        await m.cleanup();
    }
}
github faastjs / faast.js / examples / map-buckets.ts View on Github external
export async function emptyBucket(Bucket: string) {
    const faastModule = await faast("aws", m, {
        memorySize: 256,
        timeout: 300,
        mode: "https",
        concurrency: 1
    });
    const objects = await listAllObjects(Bucket);
    console.log(`Emptying Bucket ${Bucket} with ${objects.length} keys`);
    const promises: Promise[] = [];
    while (true) {
        const keys = objects.splice(0, 100).map(obj => obj.Key!);
        if (keys.length === 0) {
            break;
        }
        promises.push(faastModule.functions.deleteObjects(Bucket, keys));
    }
    await Promise.all(promises);
github faastjs / faast.js / examples / map-buckets.ts View on Github external
export async function mapObjects(Bucket: string, Keys: string[]) {
    const faastModule = await faast("aws", m, {
        memorySize: 1728,
        timeout: 300,
        mode: "https",
        concurrency: 1
    });
    for (const Key of Keys) {
        await faastModule.functions
            .processBucketObject(Bucket, Key)
            .catch(err => console.error(err));
        console.log(`Processed ${Bucket}/${Key}`);
    }
    await faastModule.cleanup();
}