Skip to main content

event-normalizer

Middleware for iterating through an AWS event records, parsing and normalizing nested events.

AWS Events Transformations: https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html

Event SourceIncludedComments
AlexaNoNormalization not required
API Gateway (HTTP)No *See middleware prefixed with @middy/http-
API Gateway (REST)No *See middleware prefixed with @middy/http-
API Gateway (WS)No *See middleware @middy/ws-json-body-parser
Application LBNo *See middleware prefixed with @middy/http-
CloudFormationNoNormalization not required
CloudFrontNoNormalization not required
CloudTrailNoNormalization not required
CloudWatch AlarmNoNormalization not required
CloudWatch LogsYesBase64 decode and JSON parse data
CodeCommitNoNormalization not required
CodePipelineYesJSON parse UserParameters
CognitoNoNormalization not required
ConfigYesJSON parse invokingEvent and ruleParameters
ConnectNoNormalization not required
DocumentDBNoNormalization not required
DynamoDBYesUnmarshall Keys, OldImage, and NewImage
EC2NoNormalization not required
EventBridgeNoNormalization not required
IoTNoNormalization not required
IoT EventNoNormalization not required
KafkaYesBase64 decode and JSON parse value
Kafka (MSK)YesBase64 decode and JSON parse value
Kinesis FirehoseYesBase64 decode and JSON parse data
Kinesis StreamYesBase64 decode and JSON parse data
LexNoNormalization not required
MQYesBase64 decode and JSON parse data
RDSNoNormalization not required
S3YesURI decode key
S3 BatchYesURI decode s3Key
S3 Object LambdaNo *See middleware @middy/s3-object-response
Secrets ManagerNoNormalization not required
SESNoNormalization not required
SNSYesJSON parse Message
SQSYesJSON parse body
VPC LatticeNo *See middleware prefixed with @middy/http-

* Handled in another dedicated middleware(s)

Test Events Some events send test events after set, you will need to handle these.

// S3 Test Event
{
Service: 'Amazon S3',
Event: 's3:TestEvent',
Time: '2020-01-01T00:00:00.000Z',
Bucket: 'bucket-name',
RequestId: '***********',
HostId: '***/***/***='
}

Install

To install this middleware you can use NPM:

npm install --save @middy/event-normalizer

Options

  • wrapNumbers (boolean) (default undefined): Whether to return numbers as a string instead of converting them to native JavaScript numbers. This allows for the safe round-trip transport of numbers of arbitrary size. For DynamoDB Events only.

Sample usage

import middy from '@middy/core'
import eventNormalizer from '@middy/event-normalizer'

const lambdaHandler = (event, context) => {
const { Records } = event
for (const record of Records) {
// ...
}
}

export const handler = middy().use(eventNormalizer()).handler(lambdaHandler)