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

@janiscommerce/s3-listener

v1.1.1

Published

![Build Status](https://github.com/janis-commerce/s3-listener/workflows/Build%20Status/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/janis-commerce/s3-listener/badge.svg?branch=master)](https://coveralls.io/github/janis-commerce/s3-list

Downloads

192

Readme

s3-listener

Build Status Coverage Status npm version

A package to handle the s3 event

Installation

npm install @janiscommerce/s3-listener

Configuration

If you are working with serverless framework and want to use the serverless-s3-local plugin you need to config the environment variable S3_LOCAL_ENDPOINT

provider:
  environment:
    S3_LOCAL_ENDPOINT: http://localhost:{serverless-s3-local-port}
provider:
  environment:
    S3_LOCAL_ENDPOINT: http://localhost:30232

custom:
  s3:
    port: 30232
    directory: ./tmp

S3Listener

This is the class you should extend to code your own Listeners. You can customize them with the following methods and getters:

async process()

This method is required, and should have the logic of your Listener.

The following methods will be inherited from the base Listener Class:

async getData()

This method should return the data inside the S3 file (object) who generates the S3 event.

Getters

  • bucketName (getter). Returns the name of the S3 bucket where the event is generated

  • fileKey (getter). Returns the key of the S3 object (file). This fileKey prop returns the filePrefix + filename + fileExtensions

  • filename (getter). Returns the name of the file (S3 object).

  • filePrefix (getter). Returns the prefix of the file (S3 object).

  • fileExtension (getter). Returns the extention of the file (S3 object).

  • filesize (getter). Returns the size of the file (S3 object).

  • fileTag (getter). Returns the eTag of the file (S3 object).

ServerlessHandler

This is the class you should use as a handler for your AWS Lambda functions.

async handle(Listener, event, context, callback)

This will handle the lambda execution.

  • Listener {Class} The event listener class. It's recommended to extend from this package EventListener class.
  • event {object} The lambda event object
  • context {object} The lambda context object
  • callback {function} The lambda callback function

ServerlessHandlerError

Handled errors of the S3 Event or runtime errors inside process. If the error was emit on the process method you might find more information about the error source in the previousError property.

It also uses the following error codes:

| Name | Value | Description | | --- | --- | --- | | INVALID_EVENT | 1 | The s3 event is empty or invalid | | INVALID_RECORDS | 2 | The Records of the event are empty or invalid | | INVALID_S3_RECORD | 3 | The S3 Records of the event are empty or invalid | | PROCESS_NOT_FOUND | 4 | The process method is not implemented in the event listener class | | INTERNAL_ERROR | 5 | Errors generated in the event listener class process method |

Examples

Basic Listener

'use strict';

const {
	S3Listener,
	ServerlessHandler
} = require('@janiscommerce/s3-listener');

class MyS3EventListener extends S3Listener {

	async process() {
		/* ... Your code to process the s3 event was here ... */
	}

}

module.exports.handler = (...args) => ServerlessHandler.handle(MyS3EventListener, ...args);

Get Data

'use strict';

const {
	S3Listener,
	ServerlessHandler
} = require('@janiscommerce/s3-listener');

class MyS3EventListener extends S3Listener {

	async process() {
		const data = await this.getData();
		/* ... Your code to process the s3 event was here ... */
	}

}

module.exports.handler = (...args) => ServerlessHandler.handle(MyS3EventListener, ...args);