Skip to content

Repository files navigation

Lambda Event Parser

Build Status

A simple parse tool to parse the events triggering your AWS Lambda into a common format, so you don't have to worry.

Setup Instructions

Install package to your project

npm install lambda-event-parse

or

yarn add lambda-event-parse

Import the package

const{ parserEvent, Event }=require('lambda-event-parse');parserEvent(incomingAWSEvent);

The standardized event format

{sourceType: "api",sourceEvent: originalEvent,records: [{userId: 123}]// array of events (with parameters as properties)}

How does it work

API Gateway GET Request Event:

?userId=456&name=someoneUnknown

{"httpMethod": "GET","queryStringParameters": {"userId": 456,"name": "someoneUnknown"}}

will be translated into ->

{sourceType: "api",sourceEvent: originalEvent,// the complete, unchanged GET request event objetrecords: [{userId: 123,name: "someoneUnknown"}]// array of events (with parameters as properties)}

Let's take another example, an S3 Event:

S3 Event:

{"Records": [{"s3": {"object": {"key": "HappyFace.jpg","size": 1024}}}]}

will be translated into:

{sourceType: "s3",sourceEvent: originalEvent,// the complete, unchanged S3 event objetrecords: [{"key": "HappyFace.jpg","size": 1024}]// array of events (with parameters as properties)}

DynamoDb Event:

{"Records": [{"eventID": "7de3041dd709b024af6f29e4fa13d34c","eventName": "INSERT","eventVersion": "1.1","eventSource": "aws:dynamodb","awsRegion": "us-west-2","dynamodb": {"ApproximateCreationDateTime": 1479499740,"Keys": {"Timestamp": {"S": "2016-11-18:12:09:36"},"Username": {"S": "John Doe"}},"NewImage": {"Timestamp": {"S": "2016-11-18:12:09:36"},"Message": {"S": "This is a bark from the Woofer social network"},"Username": {"S": "John Doe"}},"SequenceNumber": "13021600000000001596893679","SizeBytes": 112,"StreamViewType": "NEW_IMAGE"},"eventSourceARN": "arn:aws:dynamodb:us-east-1:123456789012:table/BarkTable/stream/2016-11-16T20:42:48.104"}]}

will be translated into:

{sourceType: "dynamodb",sourceEvent: originalEvent,// the complete, unchanged dynamodb event objetrecords: [{key: "HappyFace.jpg",size: 1024}]// array of events (with parameters as properties)}

API Gateway Event:

{"httpMethod": "GET","pathParameters": {"id": 1,"name": "test"},"queryStringParameters": {"search": "Happy Face"}}

will be translated into:

{sourceType: "api",sourceEvent: originalEvent,records: [{key: "HappyFace.jpg",size: 1024}]}

Direct Invoke Event:

[1,2,3];//array

will be translated into:

{sourceType: "invoke",sourceEvent: originalEvent,records: [1,2,3]}

Direct Invoke Event:

{"pokemon": ["pikachu","sudowoodo"]//object}

will be translated into:

{sourceType: "invoke",sourceEvent: originalEvent,records: [{"pokemon": ["pikachu","sudowoodo"]}]}

Supported AWS Events (so far)

  • SNS
  • S3
  • API Gateway (GET, POST, PUT, DELETE, PATCH)
  • DynamoDB Streams (NEW_IMAGE)
  • SQS
  • Other AWS Lambda
  • CloudWatch
  • Kinesis Data Firehose
  • Kinesis Data Streams
  • SES

License

MIT

Aleksandar Simovic

About

A parse tool that helps you easily consume any AWS resource event triggering your AWS Lambda.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages