stream-events.js
function _validateDynamoDBStreamEventRecord(record) {
  if (!isDynamoDBEventNameValid(record)) {
    throw new Error(`Invalid eventName property (${record.eventName}) for DynamoDB stream event record (${record.eventID})`);
  }
  if (!record.dynamodb) {
    throw new Error(`Missing dynamodb property for DynamoDB stream event record (${record.eventID})`);
  }
  if (!record.dynamodb.Keys) {
    throw new Error(`Missing Keys property for DynamoDB stream event record (${record.eventID})`);
  }
  if (!record.dynamodb.SequenceNumber) {
    throw new Error(`Missing SequenceNumber property for DynamoDB stream event record (${record.eventID})`);
  }
  if (!record.dynamodb.StreamViewType) {
    throw new Error(`Missing StreamViewType property for DynamoDB stream event record (${record.eventID})`);
  }
  switch (record.dynamodb.StreamViewType) {
    case 'KEYS_ONLY':
      break;

    case 'NEW_IMAGE':
      if (!record.dynamodb.NewImage && record.eventName !== 'REMOVE') {
        throw new Error(`Missing NewImage property for DynamoDB stream event record (${record.eventID})`);
      }
      break;

    case 'OLD_IMAGE':
      if (!record.dynamodb.OldImage && record.eventName !== 'INSERT') {
        throw new Error(`Missing OldImage property for DynamoDB stream event record (${record.eventID})`);
      }
      break;

    case 'NEW_AND_OLD_IMAGES':
      if ((!record.dynamodb.NewImage && record.eventName !== 'REMOVE') || (!record.dynamodb.OldImage && record.eventName !== 'INSERT')) {
        throw new Error(`Missing both NewImage and OldImage properties for DynamoDB stream event record (${record.eventID})`);
      }
      break;

    default:
      throw new Error(`Unexpected StreamViewType (${record.dynamodb.StreamViewType}) on DynamoDB stream event record (${record.eventID})`);
  }
}
function _validateDynamoDBStreamEventRecord(record) {
  if (!isDynamoDBEventNameValid(record)) {
    throw new Error(`Invalid eventName property (${record.eventName}) for DynamoDB stream event record (${record.eventID})`);
  }
  if (!record.dynamodb) {
    throw new Error(`Missing dynamodb property for DynamoDB stream event record (${record.eventID})`);
  }
  if (!record.dynamodb.Keys) {
    throw new Error(`Missing Keys property for DynamoDB stream event record (${record.eventID})`);
  }
  if (!record.dynamodb.SequenceNumber) {
    throw new Error(`Missing SequenceNumber property for DynamoDB stream event record (${record.eventID})`);
  }
  if (!record.dynamodb.StreamViewType) {
    throw new Error(`Missing StreamViewType property for DynamoDB stream event record (${record.eventID})`);
  }
  switch (record.dynamodb.StreamViewType) {
    case 'KEYS_ONLY':
      break;

    case 'NEW_IMAGE':
      if (!record.dynamodb.NewImage && record.eventName !== 'REMOVE') {
        throw new Error(`Missing NewImage property for DynamoDB stream event record (${record.eventID})`);
      }
      break;

    case 'OLD_IMAGE':
      if (!record.dynamodb.OldImage && record.eventName !== 'INSERT') {
        throw new Error(`Missing OldImage property for DynamoDB stream event record (${record.eventID})`);
      }
      break;

    case 'NEW_AND_OLD_IMAGES':
      if ((!record.dynamodb.NewImage && record.eventName !== 'REMOVE') || (!record.dynamodb.OldImage && record.eventName !== 'INSERT')) {
        throw new Error(`Missing both NewImage and OldImage properties for DynamoDB stream event record (${record.eventID})`);
      }
      break;

    default:
      throw new Error(`Unexpected StreamViewType (${record.dynamodb.StreamViewType}) on DynamoDB stream event record (${record.eventID})`);
  }
}
function _validateDynamoDBStreamEventRecord ( record ) { if ( ! isDynamoDBEventNameValid ( record ) ) { throw new Error ( ` ${ record . eventName } ${ record . eventID } ` ) ; } if ( ! record . dynamodb ) { throw new Error ( ` ${ record . eventID } ` ) ; } if ( ! record . dynamodb . Keys ) { throw new Error ( ` ${ record . eventID } ` ) ; } if ( ! record . dynamodb . SequenceNumber ) { throw new Error ( ` ${ record . eventID } ` ) ; } if ( ! record . dynamodb . StreamViewType ) { throw new Error ( ` ${ record . eventID } ` ) ; } switch ( record . dynamodb . StreamViewType ) { case 'KEYS_ONLY' : break ; case 'NEW_IMAGE' : if ( ! record . dynamodb . NewImage && record . eventName !== 'REMOVE' ) { throw new Error ( ` ${ record . eventID } ` ) ; } break ; case 'OLD_IMAGE' : if ( ! record . dynamodb . OldImage && record . eventName !== 'INSERT' ) { throw new Error ( ` ${ record . eventID } ` ) ; } break ; case 'NEW_AND_OLD_IMAGES' : if ( ( ! record . dynamodb . NewImage && record . eventName !== 'REMOVE' ) || ( ! record . dynamodb . OldImage && record . eventName !== 'INSERT' ) ) { throw new Error ( ` ${ record . eventID } ` ) ; } break ; default : throw new Error ( ` ${ record . dynamodb . StreamViewType } ${ record . eventID } ` ) ; } }
Validates the given DynamoDB stream event record.
@param {DynamoDBEventRecord|*} record - a DynamoDB stream event record
@private
Validates the given DynamoDB stream event record .