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

sam-stereotype

v0.1.4

Published

NodeJS boilerplate handler, dispatch, and framework for AWS SAM

Downloads

1

Readme

sam-stereotype

NodeJS boilerplate handler, dispatch, and framework for AWS SAM

Handlers

SNS

Extracts the event.Records[0].Sns.Message to event.packet

const { snsHandler } = require('sam-stereotype');

exports.handler = snsHandler((event, context, callback) => {
  if (event.packet) {
    callback(null, `Successfully received packet: ${event.packet}`);
  }
  callback(null, `Failed to receive packet: ${event}`);
});

Other

Still working on the additional trigger handlers, while they exist, they shouldn't be used yet.

Available:

  • S3
  • Schedule

In Progress:

  • SQS
  • Kinesis
  • IOT
  • Dynamo
  • Cloudwatch Logs
  • Cloudwatch Events
  • API
  • Alexa

Dispatch

SNS

Streamlines the SNS Publish process

const { snsDispatch } = require('sam-stereotype');

exports.handler = (event, context, callback) => {
  snsDispatch('my-sns-arn', 'my-message')
    .then(()=> {
      callback(null, 'Successfully dispatched SNS Message');
    })
    .catch(e => callback(null, `Failed to dispatch SNS Message: ${e.stack}`));
};

SES

Streamlines the SES Publish process

const { sesDispatch } = require('sam-stereotype');

exports.handler = (event, context, callback) => {
  sesDispatch(
      '[email protected]',
      '[email protected]',
      'Subject',
      'Message with <b>HTML</b>'
  )
    .then(()=> {
      callback(null, 'Successfully dispatched SES Message');
    })
    .catch(e => callback(null, `Failed to dispatch SES Message: ${e.stack}`));
};

Other

Available:

  • Dynamo
  • S3

Build Framework

The build framework is a suggested Makefile and Webpack config.

Either configuration file can be used independently but the Makefile's compile requires webpack to be installed. You can use your own webpack config, read make compile for more information.

Makefile

Include the Makefile and variables in your Makefile for the suite of shortcuts.

include ./node_modules/sam-stereotype/Makefile

# S3 Bucket to upload Lambdas - Must exist before running any commands
BUCKET = sam-stereotype
# Key prefix: s3:/sam-stereotype/stereotype-files
BUCKET_PREFIX = stereotype-files
# Cloudformation stack name
STACK = sam-stereotype-stack
  • make compile

Compile will run webpack and copy a package.json file located in the ./src/ directory into each ./dist/ directory. When using the bundled webpack.config your lambda's would be compiled into the following directory structure.

./dist
  ./testLambda
    ./index.js
    ./package.json
  ./anotherLambda
    ./index.js
    ./pacakge.json
  • make validate

Validate will run sam validate

  • make build

Build will run sam build. The build command assumes a template.yaml or template.yml file is in the project root.

  • make package

Package will run build as well as sam package and output the template file to deployment.yaml

  • make deploy

Deploy will run sam deploy with the deployment.yaml to the defined stack name.

  • make push

Push will run compile, validate, build, package, and deploy.

  • make down

Down will delete the cloudformation stack.

Webpack

Require the webpack.config.js to perform lambda packing.

// webpack.config.js
module.exports = require('sam-stereotype/webpack.config');

The webpack configuration assumes there is a ./src/lambda directory with single file lambda's. Each lambda is packaged into the ./dist/{fileName} directory as index.js.

If you are using make compile, you need to create a package.json file in the ./src directory to be included in each ./dist/{lambda} directory. package.json is required in each dist directory for package to run properly.

Your template.yaml file can include the dist lambda:

Resources:
  TestSNS:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: nodejs8.10
      Handler: index.handler
      Description: Single SNS event handler test
      CodeUri: ./dist/testSns
      FunctionName: testSns
      Timeout: 15