Giter Site home page Giter Site logo

Comments (1)

rubenkaiser avatar rubenkaiser commented on August 22, 2024

Hi, can you show me your code. The consuming functions do receive the correct format:

{
  version: '0',
  id: 'xxxxxxxx-xxxx-xxxx-xxxx-1605085184180',
  source: 'acme.newsletter.campaign',
  account: '',
  time: '2020-11-11T08:59:44.180Z',
  region: 'eu-west-1',
  resources: [],
  detail: { 'E-Mail': '[email protected]' },
  'detail-type': 'UserSignUp'
}

Using the following example code:

serverless.yml:


plugins:
  - serverless-webpack
  - serverless-offline
  - serverless-offline-aws-eventbridge
  
custom:
  webpack:
    webpackConfig: ./webpack.config.js
    includeModules: true
  serverless-offline:
    host: 0.0.0.0
  serverless-offline-aws-eventbridge:
    port: 4010
    debug: true

provider:
  name: aws
  runtime: nodejs12.x
  stage: dev
  region: eu-west-1
 
functions:
  publishEvent:
    handler: events.publish
    events:
      - http:
          path: publish
          method: get

  consumeEvent:
    handler: events.consume
    events:
      - eventBridge:
          eventBus: marketing
          pattern:
            source:
              - acme.newsletter.campaign

events.js

import AWS from 'aws-sdk';

AWS.config.update({
  apiVersion: '2015-10-07',
  accessKeyId: "YOURKEY",
  secretAccessKey: "YOURSECRET",
  region: "eu-west-1"
});

export const publish = async () => {
  try {
    const eventBridge = new AWS.EventBridge({
      endpoint: 'http://127.0.0.1:4010',
      region: 'eu-west-1'
    });

    const test = await eventBridge.putEvents({
      Entries: [
        {
          EventBusName: 'marketing',
          Source: 'acme.newsletter.campaign',
          DetailType: 'UserSignUp',
          Detail: `{ "E-Mail": "[email protected]" }`,
        },
      ]
    }).promise();
  } catch (e) {
    console.error(e);
    return { statusCode: 400, body: 'could not publish' };
  }
  return { statusCode: 200, body: 'published' };
}

export const consume = async (event, context) => {
  console.log(event);
  return { statusCode: 200, body: 'consume' };
}

Using babel and webpack to transpile everything..

from serverless-offline-eventbridge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.