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

@moblybr/node-event-bridge-client

v2.0.0

Published

Pacote para uso do EventBridge da AWS

Downloads

82

Readme

@mobly/packages/node/event-bridge-client

Event Bridge

Instalação do pacote

npm i @moblybr/node-event-bridge-client

Executando

É só importar o eventBridge no lambda de publish e executar a função.

create.js - publish

import { publishEvent } from '@moblybr/node-event-bridge-client'

const handler = middy(async (event, context) => {
  ...
  // Usar Event Bridge
  const params = {
    headers: {user_status: ‘created’},
    message: { name: 'User number 1', status: 'Online', gender: 'male' },
    eventName: 'created',
    eventBusName: 'eventBustest',
    source: 'Mobly.ProductService',
    configEventBridge: { region: 'us-east-1' }
  }
  await publishEvent(messageEvent)
}

O subscriber do eventBridge recebendo a informação, acessamos a via event.detail.

created.js - subscriber

const handler = middy(async (event, context) => {
  ...

  const body = event.detail
  console.log(body)

}

Métodos

  publishEvent(params)

Parâmetros

  headers: `object`,
  message: `string` or `object`
  eventName: `string`
  eventBusName: `string`
  source: `string`
  configEventBridge: `object` (opcional)

headers

Campo disponível para os Messages Attributes usados na aplicação via SNS/SQS.

message

É a mensagem a ser transmitida via evento, sendo uma string ou um objeto JSON.

eventName

É o nome do evento disparado.

eventBusName

É o nome do eventBus usado para acessar os event desse bus específico.

source

É informado para identificar o serviço que gerou o evento.

configEventBridge

É usado para informar a região do eventBridge, por padrão é a us-east-1.

Configuração do evento no serverless.yml

É necessário dar permissões aos lambdas que irão usar o eventBridge, tanto para publicar quanto para receber o evento.

A configuração do iamRoleStatements é definida em cada lambda.

lambda publisher no serverless.yml

functions:
  createUser:
    handler: create.handler
    iamRoleStatements:
      - Effect: "Allow"
        Resource: "*"      
        Action:
          - "events:TestEventPattern"
          - "events:ListRules"
          - "events:PutEvents"

Quando criamos um lambda para receber o evento, precisamos configurar o evento de trigger junto com suas permissões.

lambda subscriber no serverless.yml

functions:
  userCreated:
    handler: created.handler
    iamRoleStatements:
        - Effect: "Allow"
          Resource: "*"      
          Action:
            - "events:TestEventPattern"
            - "events:ListRules"
    events:
      - eventBridge:
          eventBus: eventBustest
          pattern:
            source:
              - user.created