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 🙏

© 2022 – Pkg Stats / Ryan Hefner

@kakkuk/serverless-aws-lambda-dynamic-trigger

v1.0.2

Published

It allows to register triggers dynamically.

Downloads

24

Readme

serverless-aws-lambda-dynamic-trigger

The plugin can register triggers (events) for a lambda function dynamically at the time of the deployment. The usual static trigger (event) definitions can be completely omitted. The original idea is to make the same lambda function triggered by different events on different environments (stages). This way we can even do some basic feature switching.

How it works

The plugin when the host code gets deployed...

  1. Fetches the value of a defined parameter from the Parameter Store. The value must be a list ARNs separated by commas. (If there is only one trigger it's just a single ARN)
  2. Parses the individual ARNs and pulls out the name of the aws service.
  3. Registers the ARNs as triggers with the configured lambda function or functions.

Please note that you can only use the plugin with sns, sqs or kinesis triggers.

Like on dev foo lambda function is triggered by

  • arn:aws:sns:eu-west-2:123456654321:topic1
  • arn:aws:sns:eu-west-2:123456654321:topic2
  • arn:aws:sns:eu-west-2:123456654321:topic3

While on prod foo lambda function is triggered by

  • arn:aws:sns:eu-west-2:123456654321:topic1
  • arn:aws:sns:eu-west-2:123456654321:topic2

This way we can switch features on and off on different stages.

The dynamic trigger sets need to be stored in the Parameter Store of the Systems Manager (SSM) and it should look somewhat like this:

  • Name: /dev/dynamic-trigger
  • Value: arn:aws:sns:eu-west-2:123456654321:topic1,arn:aws:sns:eu-west-2:123456654321:topic2,arn:aws:sns:eu-west-2:123456654321:topic3

or

  • Name: /prod/dynamic-trigger
  • Value: arn:aws:sns:eu-west-2:123456654321:topic1,arn:aws:sns:eu-west-2:123456654321:topic2

The config parameters:

  • region: {string} the region of the Systems Manager -> Parameter Store
  • functions: {Array<name: string, ssmPath: string>}
    • name: {string} The name of the function
    • ssmPath: {string} It's actually the name of the parameter in the Parameter Store

Example

The configuration in the serverless.yml:

plugins:
  - @kakkuk/serverless-aws-lambda-dynamic-trigger
custom:
  dynamicTrigger:
    region: "eu-west-2" // !!! Optional !!! It'll fall back to AWS_DEFAULT_REGION if it's not set
    functions:
      - name: "handler1"
        ssmPath: "/${opt:stage}/trigger-set1" // This is the dynamic part :)
      - name: "handler2"
        ssmPath: "/${opt:stage}/trigger-set2" // This is the dynamic part :)

// Further down in the serverless.yml

handler1:
  handler: src/handler1
  name: ${self:service}-handler1
  // No events section needed
handler2:
  handler: src/handler1
  name: ${self:service}-handler2
  // No events section needed