Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event Data Keys Inconsistency #11

Closed
tadi-maz opened this issue Nov 11, 2020 · 1 comment
Closed

Event Data Keys Inconsistency #11

tadi-maz opened this issue Nov 11, 2020 · 1 comment
Labels
invalid This doesn't seem right

Comments

@tadi-maz
Copy link

tadi-maz commented Nov 11, 2020

Hi I've noticed that an event in EventBridge is passed in this format (as seen from cloudwatch logs):

{
    source: "some source",
    "detail-type": "some detail-type",
    detail: { someCustomDetail : "detail"}
}

whereas the plugin passes data in this format

      {
        Source: "some source",
        DetailType: "some detail-type",
        Detail:  { someCustomDetail : "detail"}
      }

Is there a way to ensure these are consistent?

@rubenkaiser
Copy link
Owner

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': 'some@someemail.some' },
  '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": "some@someemail.some" }`,
        },
      ]
    }).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..

@rubenkaiser rubenkaiser added the invalid This doesn't seem right label Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants