npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

restify-aws-lambda

v0.1.10

Published

Restified aws lambda function using TypeScript, reflect-metadata, dynamoDb, lambda-local, local-dynamo, decorators in jax-rs, spring @RestCrontroller style

Downloads

21

Readme

Introduction

This project describes a way to implement aws lambda functions in form of enterprise patterns as a multi tier application and uses dynamodb local and lambda local to simplify the local implementation. The project seperate the application into three layers. The controllers, the services and the repository (DAO layer)

The project is based on TypeScript and uses the reflect-metadata library to map the AWS lambda event to the respective controllers.

How to get start?

You can look at the "book-store" example which is in the src / domains. There you can see how an application could look like. In src / index.ts you will find an awsHandler and how to register a controller.

sh npm install

sh npm run build

Testing

Run all test
npm run test

The component tests are testing all Layers (Controller, Service and Repository). These tests build a local dynamodb on the fly and create the appropriate table you need. You can insert, select and update data in the table.

Create your Controller

When you create a new controller you need first to define the resource that match to the aws event

example aws event:

{
  "resource": "/bookstores",
  "path": "/bookstores",
  "httpMethod": "GET",
  "headers": {},
  "queryStringParameters": null,
  "pathParameters": null,
  "requestContext":
  {
    "path": "/bookstores",
    "accountId": "",
    "resourceId": "",
    "stage": "",
    "requestId": "",
    "resourcePath": "/",
    "httpMethod": "GET",
    "apiId": ""
  },
  "body": null,
  "isBase64Encoded": false
}

As you can see, the resource in this example is "/bookstores", that means your controller need to defined by the same resource: @Controller('/bookstores'). See following code:

Example Controller:

@Singleton
@Model(BookStore)
@Controller('/bookstores')
export default class BookStoreController implements IBookStoreController   {
    @Inject
    private bookStoreService: BookStoreService;

    @GET()
    public getBookStores(): Promise<IBookStore[]> {
      return this.bookStoreService.getBookStores();
    }

    @GET('/{id}')
    public getBookStoreById(@PathParam('id') id: string): Promise<IBookStore> {
      Validator.validateField('id', id, Validator.VALIDATOR_SCHEMA.UUID_REQUIRED);
      return this.bookStoreService.getBookStoreById(id);
    }

    @POST()
    public createBookStore (bookStore: IBookStore): Promise<IBookStore> {
      return this.bookStoreService.createBookStore(bookStore);
    }
    ....
}

As you can also see, you can use annotations (as in jax-rs or spring requestMapping) @GET, @POST, @PUT, @DELETE to define the routing. In addition, you can use @PathParam and @QueryParam to access the path paremeter and query paremeter

Adding new Controller in the index.ts:

ControllerRegistry.register(BookStoreController);

Thats it!

By simply registering the controllers, you no longer need to worry about mapping the aws event for the particular component, and your code remains clearly structured

Available Modules/Components

import { Model, Controller, POST, GET, PUT, PathParam, DELETE 
 ControllerRegistry, Response, QueryParam, MethodNotFoundError, NotFoundError
 ValidationError, execute, Validator, Model} from 'restify-aws-lambda';

You can import following exported methods/classes/modules like below:

| components | description | | ------------------- |:---------------------------------------------------:| | ControllerRegistry | to register a controller | | Controller | @Controller to define an new controller | | GET | HTTP GET -> @GET | | POST | HTTP POST -> @POST | | PUT | HTTP PUT -> @PUT | | DELETE | HTTP DELETE -> @DELETE | | PathParam | @PathParam to get the path paramenter | | QueryParam | @QueryParam to get the query paremeter | | execute | execute the incoming aws event | | Model | Model for example Book Store |

Please take a look of the example how you can use the below components.