Created
August 28, 2019 23:48
-
-
Save rohanmendon/8d2c5fa80a6a53ac4e03e8dc564254e2 to your computer and use it in GitHub Desktop.
Lambda to process the data stream from Kinesis in real time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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