class LambdaRunner::Events

aws events

Public Class Methods

dynamodb_event(key, new_image = nil, old_image = nil) click to toggle source
# File lib/lambda_runner.rb, line 122
def self.dynamodb_event(key, new_image = nil, old_image = nil)
  event = load_json('sample_dynamodb_event.json')
  get_dynamodb_record(event['Records'][0], key, new_image, old_image)
  event
end
s3_event(bucket, key, eventName='ObjectCreated:Put') click to toggle source
# File lib/lambda_runner.rb, line 95
def self.s3_event(bucket, key, eventName='ObjectCreated:Put')
  event = load_json('sample_s3_event.json')
  event['Records'].each do |record|
    record['eventName'] = eventName
    record['s3']['bucket'].update('name' => bucket,
                                  'arn' => 'arn:aws:s3:::' + bucket)
    record['s3']['object']['key'] = key
    record
  end
  event
end
sns_event(topicArn, messageId, timestamp, messageBody) click to toggle source
# File lib/lambda_runner.rb, line 107
def self.sns_event(topicArn, messageId, timestamp, messageBody)
  unless messageBody.kind_of? String
    messageBody = JSON.generate messageBody
  end

  event = load_json('sample_sns_event.json')
  event['Records'].each do |record|
    record['Sns']['TopicArn'] = topicArn
    record['Sns']['MessageId'] = messageId
    record['Sns']['Timestamp'] = timestamp
    record['Sns']['Message'] = messageBody
  end
  event
end

Private Class Methods

get_dynamodb_record(record, key, new_image, old_image) click to toggle source
# File lib/lambda_runner.rb, line 128
                     def self.get_dynamodb_record(record, key, new_image, old_image)
  if new_image && old_image
    record['dynamodb']['NewImage'] = new_image['NewImage']
    record['dynamodb']['OldImage'] = old_image['OldImage']
    record['eventName'] = 'MODIFY'
  elsif new_image
    record['dynamodb']['NewImage'] = new_image['NewImage']
    record['eventName'] = 'INSERT'
  else
    record['dynamodb']['OldImage'] = old_image['OldImage']
    record['eventName'] = 'REMOVE'
  end
  record['dynamodb']['Keys'] = key
  record
end
load_json(name) click to toggle source
# File lib/lambda_runner.rb, line 146
def self.load_json(name)
  base = File.dirname(File.dirname(__FILE__))
  File.open(File.join(base, "samples", name)) { |file| return JSON.load(file) }
end