Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.