AWS SDK for RubyでDynamoDBを操作してみた

AWS SDK for RubyでDynamoDBを操作してみた

JAWS-UG沖縄 CMS祭り 前夜祭LT資料です。

3174b33cfbf39090f00a4791b3780888?s=128

Naoto Enokawa

October 18, 2014
Tweet

Transcript

  1. AWS SDK for Ruby V2Ͱ DynamoDBΛૢ࡞ͯ͠Έͨ Naoto Enokawa

  2. ࣗݾ঺հ ӫ໺઒ ௚ేʢ͑ͷ͔Θ ͳ͓ͱʣ ԭೄࠃࡍେֶ4೥࣍ ಛٕɿDJʢEDMͱ͔ʣ झຯɿҰ؟ϨϑʢEOS kiss X5ʣ

  3. DynamoDBʹϦΞϧλΠϜͰ πΠʔτΛ֨ೲ͢Δ ΍ͬͨ͜ͱ

  4. ͳΜͰʁʁ

  5. None
  6. MacBookͷഎ໘Λ ࣗຫ͋͠͏WebαʔϏε

  7. ʮMacFriendsʯͰݕࡧʂ http://macfriends.net/

  8. None
  9. ઌੜʮσʔλϕʔε࢖͑ʯ

  10. DBͳʹ࢖͓͏… RDS࢖ͬͨΒෛ͚ͨײ͕͢͡Δww

  11. RDS࢖͏ΑΓDynamoDB ࢖ͬͨํ͕҆͘ࡁΈͦ͏ʂʂ

  12. ࢖༻ͨ͠AWSαʔϏε DynamoDBɿ׬શϚωʔδυNoSQLɺ KeyValueܕɺAPIܦ༝Ͱར༻͢ΔɺSSDͰ଎͍ AWS SDK for RubyɿRubyͰAWSͷϦιʔεΛ ૢ࡞͢Δ͜ͱ͕Ͱ͖Δɺଞʹ΋ɺJavaɺ JavaScriptɺPhytonɺPHPɺ.NETɺNode.jsɺ iOSɺAndroid

  13. Πϝʔδਤ DynamoDB ΅͘ͷMac RubyͰͿͪࠐΉʂʂ

  14. σϞ

  15. create_table.rb resp = dynamo_db.create_table( table_name: 'tweets', key_schema: [ { attribute_name:

    'tweet_id', key_type: 'HASH', }, ], attribute_definitions: [ { attribute_name: 'tweet_id', attribute_type: 'N', }, ], provisioned_throughput: { read_capacity_units: 1, write_capacity_units: 1, }, )
  16. put_item.rb client = TweetStream::Client.new ! client.track("#macfriends") do |status| if !status.text.index("RT")

    puts "@" + status.user.screen_name + " : " + status.text resp = dynamo_db.put_item( table_name: 'tweets', item: { 'tweet_id' => status.id, 'user_id' => status.user.id, 'screen_name' => status.user.screen_name, 'tweet_text' => status.text, } ) end end
  17. None
  18. ࠓޙͷ՝୊ • ݟ͑ΔԽ • ϒϥ΢β্ͰDBͷ৘ใΛදࣔͤ͞Δ • herokuʹσϓϩΠ

  19. None
  20. /enokawa/tweetstream_dynamodb

  21. AWS SDK for Ruby V2Ͱ DynamoDBΛૢ࡞ͯ͠Έͨ Naoto Enokawa