ruby/example_code/dynamodb/dynamodb_ruby_example_update_movies_item.rb
# Updates an item in a table in Amazon DynamoDB.
#
# @param dynamodb_client [Aws::DynamoDB::Client] An initialized
#   Amazon DynamoDB client.
# @param table_item [Hash] The properties of the item, in the correct format.
# @return [Boolean] true if the item was updated; otherwise, false.
# @example
#   exit 1 unless table_item_updated?(
#     Aws::DynamoDB::Client.new(region, 'us-west-2'),
#     {
#       table_name: 'Movies',
#       key: {
#         year: 2015,
#         title: 'The Big New Movie'
#       },
#       update_expression: 'SET info.rating = :r',
#       expression_attribute_values: { ':r': 0.1 },
#       return_values: 'UPDATED_NEW'
#     }
#   )

Updates an item in a table in Amazon DynamoDB.
Updates an item in a table in Amazon DynamoDB .
def table_item_updated?(dynamodb_client, table_item)
  response = dynamodb_client.update_item(table_item)
  puts "Table item updated with the following attributes for 'info':"
  response.attributes['info'].each do |key, value|
    if key == 'rating'
      puts "#{key}: #{value.to_f}"
    else
      puts "#{key}: #{value}"
    end
  end
  true
rescue StandardError => e
  puts "Error updating item: #{e.message}"
  false
end
def table_item_updated? ( dynamodb_client , table_item ) response = dynamodb_client . update_item ( table_item ) puts "Table item updated with the following attributes for 'info':" response . attributes [ 'info' ] . each do | key , value | if key == 'rating' puts "#{key}: #{value.to_f}" else puts "#{key}: #{value}" end end true rescue StandardError => e puts "Error updating item: #{e.message}" false end
Updates an item in a table in Amazon DynamoDB.
Updates an item in a table in Amazon DynamoDB .
true if the item was updated; otherwise, false.
true if the item was updated ; otherwise false .
Boolean
dynamodb_client
An initialized Amazon DynamoDB client.
An initialized Amazon DynamoDB client .
table_item
The properties of the item, in the correct format.
The properties of the item in the correct format .
example
exit 1 unless table_item_updated?( Aws::DynamoDB::Client.new(region, 'us-west-2'), { table_name: 'Movies', key: { year: 2015, title: 'The Big New Movie' }, update_expression: 'SET info.rating = :r', expression_attribute_values: { ':r': 0.1 }, return_values: 'UPDATED_NEW' } )
exit 1 unless table_item_updated? ( Aws :: DynamoDB :: Client . new ( region ' us - west - 2 ' ) { table_name : ' Movies ' key : { year : 2015 title : ' The Big New Movie ' } update_expression : ' SET info . rating = : r ' expression_attribute_values : { ' : r ' : 0 . 1 } return_values : ' UPDATED_NEW ' } )