There are more AWS SDK examples available in the AWS Doc SDK Examples
Amazon MSK examples using SDK for Ruby
The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for Ruby with Amazon MSK.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Serverless examples
The following code example shows how to implement a Lambda function that receives an event triggered by receiving records from an Amazon MSK cluster. The function retrieves the MSK payload and logs the record contents.
- SDK for Ruby
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Serverless examples
repository. Consuming an Amazon MSK event with Lambda using Ruby.
require 'base64' def lambda_handler(event:, context:) # Iterate through keys event['records'].each do |key, records| puts "Key: #{key}" # Iterate through records records.each do |record| puts "Record: #{record}" # Decode base64 msg = Base64.decode64(record['value']) puts "Message: #{msg}" end end end