SlideShare uma empresa Scribd logo
1 de 28
Baixar para ler offline
Ruby
on
Amazon DynamoDB #1
Hamamatsu.rb, @jacoyutorius 1
About
Hamamatsu.rb, @jacoyutorius 2
{
"name": "yuto ogi",
"twitter": "@jacoyutorius",
"skills": ["ruby", "javascript", "aws"],
"note": "AWS SAM localが気になります"
}
Hamamatsu.rb, @jacoyutorius 3
Amazon DynamoDB
4 フルマネージド型NoSQLデータベース
Hamamatsu.rb, @jacoyutorius 4
RDBとの違い
4 スケールのしかた
4 RDBは垂直方向、DynamoDBは水平方向
Hamamatsu.rb, @jacoyutorius 5
scaleup
4 マシンのメモリやディスクサイズを
拡張
Hamamatsu.rb, @jacoyutorius 6
scaleout
4 同じスペックの複製を作成して並
列化
Hamamatsu.rb, @jacoyutorius 7
用語の違い
SQL DynamoDB MongoDB
テーブル テーブル コレクション
行 項目 ドキュメント
列 属性 フィールド
PK PK ObjectId
Index セカンダリインデックス インデックス
Hamamatsu.rb, @jacoyutorius 8
Amazon DynamoDB
4 パーティションキーとソートキー
4 パーティションキー
4 いわゆるハッシュのKey
4 ソートキー
4 パーティションキーとソートキーの2つのキーの組み合
わせでレコードを一意に識別する
Hamamatsu.rb, @jacoyutorius 9
DynamoDB local
4 ローカルで実行できるDynamoDB
(Management ConsoleのGUIが使いやすいのでわざわざlocalでやる必要ないかも)
Hamamatsu.rb, @jacoyutorius 10
DynamoDB local
ダウンロードするだけ。 Java必要。
$java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
Hamamatsu.rb, @jacoyutorius 11
start DynamoDB local
$curl localhost:8000
{
"__type":"com.amazonaws.dynamodb.v20120810#MissingAuthenticationToken",
"message":"Request must contain either a valid (registered) AWS access key ID or X.509 certificate."
}
または、http://localhost:8000/shell/
Hamamatsu.rb, @jacoyutorius 12
結論
『辛い』
Hamamatsu.rb, @jacoyutorius 13
gems
4 aws/aws-sdk-ruby
4 aws/aws-sdk-ruby-record
Hamamatsu.rb, @jacoyutorius 14
Aws::Record
4 ruby製のDynamoDBクライアントgem
4 DynamoDBのテーブルとRubyのクラスをマッピング
4 ActiveRecordっぽく操作できる
(無理して使うこともないかな・・・)
Hamamatsu.rb, @jacoyutorius 15
setup
require "aws-sdk"
require "aws-record"
Aws.config.update(endpoint: "http://localhost:8000")
client = Aws::DynamoDB::Client.new
Hamamatsu.rb, @jacoyutorius 16
table
class Music
set_table_name :Music
string_attr :artist, hash_key: true
string_attr :song_title, range_key: true
string_attr :album_title
end
4 artistをハッシュキー、song_titleをソートキー。
4 2つの値でレコードを一意に識別する。
Hamamatsu.rb, @jacoyutorius 17
Artist
id name
1 AJICO
2 Bill Evans
3 Cream
class Artist
set_table_name :Artist
integer_attr :id, hash_key: true
string_attr :name
end
Hamamatsu.rb, @jacoyutorius 18
Album
artist title
AJICO AJICO SHOW
Bill Evans Portrait in JAZZ
Bill Evans Waltz for Debby
Cream BBC Sessions
class Album
set_table_name :Album
string_attr :artist, hash_key: true
string_attr :title, range_key: true
end
Hamamatsu.rb, @jacoyutorius 19
Song
artist song_title album_title
Bill Evans Waltz for Debby Waltz for Debby
Bill Evans Detour Ahead Waltz for Debby
Bill Evans Autumn Leaves Portrait in JAZZ
class Song
set_table_name :Song
string_attr :artist, hash_key: true
string_attr :song_title, range_key: true
string_attr :album_title
end
Hamamatsu.rb, @jacoyutorius 20
migration
テーブルの作成
migration = Aws::Record::TableMigration.new(Music, client: client)
migration.create!(
provisioned_throughput: {
read_capacity_units: 5,
write_capacity_units: 2
}
)
migration.wait_until_available
Hamamatsu.rb, @jacoyutorius 21
putitem
レコードのインサート
music = Music.new(
artist: "Primal Scream",
song_title: "Where The Light Gets In",
album_title: "Chaosmosis")
music.save!
=> <struct Aws::DynamoDB::Types::PutItemOutput attributes=nil,
consumed_capacity=nil,
item_collection_metrics=nil>
Hamamatsu.rb, @jacoyutorius 22
scan
テーブルの検索
music = Music.scan
music.each do |row|
puts row.name
end
#=> "Primal Scream"
Hamamatsu.rb, @jacoyutorius 23
query
テーブルの検索
params = {
table_name: "Music",
key_conditions: {
"artist" => {
attribute_value_list: ["Foo Fighters"],
comparison_operator: "EQ"
}
}
}
musics = Music.query(params)
musics.each do |row|
p row.song_title
end
Hamamatsu.rb, @jacoyutorius 24
find
テーブルのプライマリキーからレコードを抽出する。
pp Music.find(artist: "Bill Evans", song_title: "Autumn Leaves")
#<Music:0x007f84a8d2e248
@data=
#<Aws::Record::ItemData:0x007f84a8d2e180
@clean_copies=
{:artist=>"Bill Evans",
:song_title=>"Autumn Leaves",
:album_title=>"(1969)Autumn Leaves",
:favorite=>nil}, ...
Hamamatsu.rb, @jacoyutorius 25
impressions
4 RDBとは全く異なるので大変
4 今のところDynamoDBじゃなければいけないデータを扱
うことは無いのでテーブル設計のイメージがしずらい
4 わざわざRubyでやることも無いかな(LambdaのRuby対応
が来ればもしくは)
4 NodeかPython使えばいいのでは
Hamamatsu.rb, @jacoyutorius 26
reference
4 https://aws.amazon.com/jp/dynamodb/
Hamamatsu.rb, @jacoyutorius 27
to be continued
=> https://gist.github.com/jacoyutorius/
4b8f265cfb541e342cc7749fd8900610
Hamamatsu.rb, @jacoyutorius 28

Mais conteúdo relacionado

Mais procurados

Web application security & Testing
Web application security  & TestingWeb application security  & Testing
Web application security & Testing
Deepu S Nath
 
Cross Site Request Forgery (CSRF) Scripting Explained
Cross Site Request Forgery (CSRF) Scripting ExplainedCross Site Request Forgery (CSRF) Scripting Explained
Cross Site Request Forgery (CSRF) Scripting Explained
Valency Networks
 

Mais procurados (20)

효과적인 NoSQL (Elasticahe / DynamoDB) 디자인 및 활용 방안 (최유정 & 최홍식, AWS 솔루션즈 아키텍트) :: ...
효과적인 NoSQL (Elasticahe / DynamoDB) 디자인 및 활용 방안 (최유정 & 최홍식, AWS 솔루션즈 아키텍트) :: ...효과적인 NoSQL (Elasticahe / DynamoDB) 디자인 및 활용 방안 (최유정 & 최홍식, AWS 솔루션즈 아키텍트) :: ...
효과적인 NoSQL (Elasticahe / DynamoDB) 디자인 및 활용 방안 (최유정 & 최홍식, AWS 솔루션즈 아키텍트) :: ...
 
Cyber ppt
Cyber pptCyber ppt
Cyber ppt
 
WordPress Security for Beginners
WordPress Security for BeginnersWordPress Security for Beginners
WordPress Security for Beginners
 
Web application security & Testing
Web application security  & TestingWeb application security  & Testing
Web application security & Testing
 
OWASP Top Ten API Project 2019
OWASP Top Ten API Project 2019OWASP Top Ten API Project 2019
OWASP Top Ten API Project 2019
 
Security Testing
Security TestingSecurity Testing
Security Testing
 
Click jacking
Click jackingClick jacking
Click jacking
 
Petit potam slides-rtfm-ossir
Petit potam slides-rtfm-ossirPetit potam slides-rtfm-ossir
Petit potam slides-rtfm-ossir
 
Session fixation
Session fixationSession fixation
Session fixation
 
Mona cheatsheet
Mona cheatsheetMona cheatsheet
Mona cheatsheet
 
Cross Site Request Forgery (CSRF) Scripting Explained
Cross Site Request Forgery (CSRF) Scripting ExplainedCross Site Request Forgery (CSRF) Scripting Explained
Cross Site Request Forgery (CSRF) Scripting Explained
 
Using AWS Purpose-Built Databases to Modernize your Applications
Using AWS Purpose-Built Databases to Modernize your ApplicationsUsing AWS Purpose-Built Databases to Modernize your Applications
Using AWS Purpose-Built Databases to Modernize your Applications
 
Introduction to Windows Dictionary Attacks
Introduction to Windows Dictionary AttacksIntroduction to Windows Dictionary Attacks
Introduction to Windows Dictionary Attacks
 
Owasp Top 10 - A1 Injection
Owasp Top 10 - A1 InjectionOwasp Top 10 - A1 Injection
Owasp Top 10 - A1 Injection
 
Brute Force Attack Security Use Case Guide
Brute Force Attack Security Use Case Guide	Brute Force Attack Security Use Case Guide
Brute Force Attack Security Use Case Guide
 
Corporate Secret Challenge - CyberDefenders.org by Azad
Corporate Secret Challenge - CyberDefenders.org by AzadCorporate Secret Challenge - CyberDefenders.org by Azad
Corporate Secret Challenge - CyberDefenders.org by Azad
 
Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )
 
Module 19 (evading ids, firewalls and honeypots)
Module 19 (evading ids, firewalls and honeypots)Module 19 (evading ids, firewalls and honeypots)
Module 19 (evading ids, firewalls and honeypots)
 
Portfolio website
Portfolio websitePortfolio website
Portfolio website
 
Polyglot payloads in practice by avlidienbrunn at HackPra
Polyglot payloads in practice by avlidienbrunn at HackPraPolyglot payloads in practice by avlidienbrunn at HackPra
Polyglot payloads in practice by avlidienbrunn at HackPra
 

Mais de Yuto Ogi

Hamamatsurb#30
Hamamatsurb#30Hamamatsurb#30
Hamamatsurb#30
Yuto Ogi
 
Introducing aws ruby sdk
Introducing aws ruby sdkIntroducing aws ruby sdk
Introducing aws ruby sdk
Yuto Ogi
 
20130310 jaws tokai2013
20130310 jaws tokai201320130310 jaws tokai2013
20130310 jaws tokai2013
Yuto Ogi
 

Mais de Yuto Ogi (12)

Rails application template
Rails application templateRails application template
Rails application template
 
s3_website
s3_websites3_website
s3_website
 
OSC浜名湖2016 Hamamatsu.rbの歩みとITコミュニティとの上手な関わり方
OSC浜名湖2016 Hamamatsu.rbの歩みとITコミュニティとの上手な関わり方OSC浜名湖2016 Hamamatsu.rbの歩みとITコミュニティとの上手な関わり方
OSC浜名湖2016 Hamamatsu.rbの歩みとITコミュニティとの上手な関わり方
 
itamaeで一撃サーバーProvisioning
itamaeで一撃サーバーProvisioningitamaeで一撃サーバーProvisioning
itamaeで一撃サーバーProvisioning
 
浜松Ruby会議01
浜松Ruby会議01浜松Ruby会議01
浜松Ruby会議01
 
DMLを実行するrubyスクリプトをmigrationファイルのように管理するRailsプラグインを作った
DMLを実行するrubyスクリプトをmigrationファイルのように管理するRailsプラグインを作ったDMLを実行するrubyスクリプトをmigrationファイルのように管理するRailsプラグインを作った
DMLを実行するrubyスクリプトをmigrationファイルのように管理するRailsプラグインを作った
 
Web制作者のためのサーバー勉強会@沼津
Web制作者のためのサーバー勉強会@沼津Web制作者のためのサーバー勉強会@沼津
Web制作者のためのサーバー勉強会@沼津
 
Hamamatsurb#30
Hamamatsurb#30Hamamatsurb#30
Hamamatsurb#30
 
Introducing aws ruby sdk
Introducing aws ruby sdkIntroducing aws ruby sdk
Introducing aws ruby sdk
 
20130310 jaws tokai2013
20130310 jaws tokai201320130310 jaws tokai2013
20130310 jaws tokai2013
 
20130112_出張JAWSUG浜松_Androidの会浜松支部
20130112_出張JAWSUG浜松_Androidの会浜松支部20130112_出張JAWSUG浜松_Androidの会浜松支部
20130112_出張JAWSUG浜松_Androidの会浜松支部
 
リーダブルコード 第二章
リーダブルコード 第二章リーダブルコード 第二章
リーダブルコード 第二章
 

Ruby with AWS DynamoDB