1.2.0 • Published 4 months ago

@quantum-sec/sls-utils v1.2.0

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
4 months ago

sls-utils

Utilities for projects using Serverless Framework.

Declarative Config with TypeScript Decorators

Using meta decorators and the serverless.ts scaffolding, you can maintain declare Lambda handlers and their associated triggers in code. To do this, add the appropriate decorators to the handler class. Handler classes must be suffixed with .handler.ts.

import { HttpGet, KeepWarm, HttpLambdaBase, LambdaPipeline } from '@quantum-sec/sls-utils';

@KeepWarm()
@HttpGet('users')
export class GetUsersHandler extends HttpLambdaBase {
  public async handleRequest(event: any, context: any): Promise<any> {
    return this.ok({
      users: [{
        firstName: 'Obiwan',
        lastName: 'Kenobi',
      }],
    });
  }
}

module.exports.handleRequest = LambdaPipeline.create(new GetUsersHandler());

Then in your serverless.ts file:

import { ServerlessConfig } from '@quantum-sec/sls-utils';

module.exports = new Promise((resolve) => {
  new ServerlessConfig({
    name: 'example-service',
  }).generateConfig().then((config) => {
    resolve(config);
  });
});

HTTP Events

The following decorators are available to bind HTTP events to handlers:

  • @HttpGet(path: string)
  • @HttpPost(path: string)
  • @HttpPut(path: string)
  • @HttpPatch(path: string)
  • @HttpDelete(path: string)
  • @HttpEvent(method: string, path: string)

Websocket Events

The following decorators are available to bind websocket events to handlers:

  • @WebsocketEvent(route: string)
  • @WebsocketEvent(route: string, routeResponseSelectionExpression: string)

Schedule Events

The following decorators are available to bind schedule events to handlers:

S3 Events

  • @S3Created(bucket: string, prefix?: string, suffix?: string)
  • @S3Removed(bucket: string, prefix?: string, suffix?: string)
  • @S3Event(bucket: string, event: S3EventKey, prefix?: string, suffix?: string)

SNS Events

  • @SnsEvent(topic: string) (topic may be the ARN of an existing topic or the name of a topic that Serverless will create for you)

Utility Decorators

  • @KeepWarm (creates a 1 minute heartbeat that the LambdaPipeline will intercept and no-op but keep the function primed)
1.2.0

4 months ago

1.1.9

2 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago