I’m using the Ruby SDK aws-sdk-dynamodb
with Ruby 2.5 for an AWS Lambda function that saves an item to an AWS DynamoDB table.
I can successfully save an item with this code:
def save!
hash = {
table_name: ‘my-table’,
item: {
message_sid: '123456',
created_at: Time.now.to_s
}
}
dynamo = Aws::DynamoDB::Client.new(region: ‘us-east-1’)
dynamo.put_item(hash)
puts 'item successfully saved'
true
rescue => error
puts "Unable to save item: #{error}: #{error.message}"
false
end
I get an error “no such member :message_sid” when I use this code:
def save!
dynamoDB = Aws::DynamoDB::Resource.new(region: ‘us-east-1’)
table = dynamoDB.table(‘my-table’)
hash = { message_sid: '123456', created_at: Time.now.to_s }
table.put_item(hash)
puts 'item successfully saved'
true
rescue => error
puts "Unable to save item: #{error}: #{error.message}"
false
end
I haven’t found any DynamoDB documentation for the error “no such member”. Why does the second example fail?