Skip to content

Instantly share code, notes, and snippets.

@rohanmendon
Created August 28, 2019 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rohanmendon/8d2c5fa80a6a53ac4e03e8dc564254e2 to your computer and use it in GitHub Desktop.
Save rohanmendon/8d2c5fa80a6a53ac4e03e8dc564254e2 to your computer and use it in GitHub Desktop.
Lambda to process the data stream from Kinesis in real time
require 'json'
require 'base64'
require 'aws-sdk-s3'
def lambda_handler(event:, context:)
region = ''
bucket_name = ''
access_key = ''
secret_key = ''
resource = Aws::S3::Resource.new(region: region, credentials: Aws::Credentials.new(access_key, secret_key))
bucket = resource.bucket(bucket_name)
key = "projectbuddy/vehicle"
puts "event['Records'] = #{event['Records'].size}"
event['Records']&.each do |record|
puts "record['kinesis']['data'] = #{record['kinesis']['data']}"
payload = Base64.decode64(record['kinesis']['data'])
puts "Decoded payload: #{payload}"
bucket.put_object(key: "#{key}/#{Time.now.to_i}", body: payload)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment