npm.io
1.0.3 • Published 5 years ago

inversify-lambda-utils

Licence
ISC
Version
1.0.3
Deps
3
Size
26 kB
Vulns
1
Weekly
0
Stars
1

Inversify Lambda Utils

To provide IoC & DI for Lambda Applications.

Usage

Create a Lambda Function Collection

@lambda()
export class GetUserLambda extends BaseLambda {

    @handler('TestHandler')
    async handle(context: ILambdaContext<SomeBodyType>): Promise<ApiGatewayResponse> {
        return {
            statusCode: 200,
            body: JSON.stringify({ Hello: 'World' }),
            headers: {}
        };
    }

}
Generate the Lambda Handlers

(index.ts)

// You have to import reflect-metadata as first import statement
import 'reflect-metadata';
// Remember to import the lambda class once to get it registered in the Reflect
import { GetUserLambda } from './get-user-lambda';
// ... some other imports

container = new Container();

const lambdaManager = new LambdaManager(container);

export = lambdaManager.build();

To Run Your Lambda Locally: tsc && lambda-local -l dist/index.js -h TestHandler -e sample-events/empty.json

Keywords