Skip to content

Instantly share code, notes, and snippets.

@arnab
Created October 18, 2010 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnab/632917 to your computer and use it in GitHub Desktop.
Save arnab/632917 to your computer and use it in GitHub Desktop.
SimpleDB put_attributes using fog
require "fog"
CREDS_FILE = 'Somewhere'
DOMAIN = 'Dogs'
ATTRIBS_TO_CHANGE = {
'color' => 'white'
}
OPTIONS = {
:replace => ['color'],
:expect => {
'color' => 'blue'
}
}
SELECT_QUERY = "select name, age, color from #{DOMAIN} where color = 'blue'"
def creds
creds = File.readlines(CREDS_FILE)
creds.map! { |c| c.chomp }
{
:aws_access_key_id => creds[0],
:aws_secret_access_key => creds[1],
}
end
sdb = Fog::AWS::SimpleDB.new(creds)
target_items = sdb.select(SELECT_QUERY).body['Items']
puts "Found #{target_items.size} items to replace. Continue? [y/n]"
STDOUT.flush
confirmation = gets
if confirmation.chomp.downcase == 'y'
target_items.each_pair do |item_name, item|
puts "Working on #{item_name} which has attribs: #{item.inspect}"
sdb.put_attributes(DOMAIN, item_name, ATTRIBS_TO_CHANGE, OPTIONS)
puts "Done"
end
else
puts "Doing nothing"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment