aws-lambda-upload
Version:
Package and upload an AWS lambda with its minimal dependencies
86 lines (85 loc) • 3.9 kB
TypeScript
/// <reference types="node" />
import * as fse from "fs-extra";
export interface ILogger {
info(message?: string, ...optionalParams: any[]): void;
debug(message?: string, ...optionalParams: any[]): void;
}
export interface ICollectOpts {
browserifyArgs?: string[];
logger?: ILogger;
tsconfig?: string;
nodePath?: string;
cache?: ZipFileCache;
}
/**
* Run a command, returning a promise resolved on success. Similar to promisified
* child_process.execFile(), but allows overriding options.stdio, and defaults them to 'inherit'
* (to display the command's output).
*/
export declare function spawn(command: string, args: string[], options?: any): Promise<void>;
export declare type ZipFileCache = Map<string, string>;
/**
* Walk topDir directory recursively, calling cb(path, stat) for each entry found.
* If cb() return a promise, it will be waited on before proceeding.
* Visits the tree in lexocographical order, and visits directories before their children.
*/
export declare function fsWalk(topDir: string, cb: (fpath: string, stat: fse.Stats) => void): Promise<void>;
/**
* Collect and package lambda code starting at the entry file startPath, to a local zip file at
* outputZipPath. Will overwrite the destination if it exists. Returns outputZipPath.
*/
export declare function packageZipLocal(startPath: string, outputZipPath: string, options?: ICollectOpts): Promise<string>;
export interface IS3Opts extends ICollectOpts {
region?: string;
s3Bucket?: string;
s3Prefix?: string;
s3EndpointUrl?: string;
}
export interface IS3Location {
bucket: string;
key: string;
}
/**
* Collect and package lambda code and upload it to S3.
* @return Promise for the object {bucket, key} describing the location of the uploaded file.
*/
export declare function packageZipS3(startPath: string, options?: IS3Opts): Promise<IS3Location>;
export interface ILambdaOpts extends ICollectOpts {
region?: string;
lambdaEndpointUrl?: string;
}
/**
* Collect lambda code, and use it to update AWS Lambda function of the given name.
* @return {Object} Promise for the response as returned by AWS Lambda UpdateFunctionCode.
* See http://docs.aws.amazon.com/lambda/latest/dg/API_UpdateFunctionCode.html
*/
export declare function updateLambda(startPath: string, lambdaName: string, options?: ILambdaOpts): Promise<any>;
/**
* Parse the CloudFormation template at the given path (must be in JSON or YAML format), package
* any code mentioned in it to S3, replace template references with S3 locations, and return the
* adjusted template object.
*
* It is similar to `aws cloudformation package` command. It recognizes these template keys:
*
* - `Code` property in `Resource` with `Type: AWS::Lambda::Function`.
* - `CodeUri` property in `Resource` with `Type: AWS::Serverless::Function`.
*
* When these contain a file path, it'll be interpreted as a JS entry file, packaged using
* `packageZipS3()`, and replaced in the output template with appropriate S3 info. The path may be
* relative to the directory containing templatePath.
*
* @param templatePath: Path to the JSON or YAML template file.
* @return The template object, with certain entries replaced with S3 locations.
*/
export declare function cloudformationPackage(templatePath: string, options?: IS3Opts): Promise<any>;
/**
* As cloudformationPackage, but writes the adjusted template to the given output file as JSON.
* See cloudformationPackage() for other parameters.
* @param outputPath: Path to the JSON output file. May be "-" for stdout.
* @return Promise that's resolved when the template has been written.
*/
export declare function cloudformationPackageOutput(templatePath: string, outputPath: string, options: any): Promise<any>;
/**
* Main entry point when used from the command line.
*/
export declare function main(): Promise<void> | undefined;