Weitere ähnliche Inhalte
Ähnlich wie AWS Black Belt Online Seminar AWS 体験ハンズオン 〜 Amazon DynamoDB テーブル作成編 〜 (20)
Mehr von Amazon Web Services Japan (20)
AWS Black Belt Online Seminar AWS 体験ハンズオン 〜 Amazon DynamoDB テーブル作成編 〜
- 1. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
1
AWS Black Belt Online Seminar
AWS体験ハンズオン
〜~ Amazon DynamoDB テーブル作成編 〜~
2017.4.26
アマゾン ウェブ サービス ジャパン株式会社
Onikata Ai
- 2. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
2
AWS Black Belt Online Seminar へようこそ!
質問を投げることができます!
• Adobe Connect の Q&A ウィンドウから、質問を書き込んでください。
(書き込んだ質問は、主催者にしか⾒見見えません)
• 今後のロードマップに関するご質問はお答えできませんのでご了了承ください。
• Twitter へツイートする際はハッシュタグ #awsblackbelt をご利利⽤用ください。
①Q&Aウィンドウ右下
のフォームに質問を
書き込んでください
②吹き出しマークで
送信してください
- 3. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
3
AWS Black Belt Online Seminar とは
AWSJ の Tech メンバーが AWS に関する様々な事を紹介するオンラインセミナーです
【⽕火曜 12:00~∼13:00】
主に AWS のソリューションや
業界カットでの使いどころなどを紹介
(例例:IoT、⾦金金融業界向け etc.)
【⽔水曜 18:00~∼19:00】
主に AWS サービスの紹介や
アップデートの解説
(例例:EC2、RDS、Lambda etc.)
• 開催曜⽇日と時間帯は変更更となる場合がございます。
• 最新の情報は下記をご確認下さい。
オンラインセミナーのスケジュール & 申し込みサイト
https://aws.amazon.com/jp/about-‐‑‒aws/events/webinars/
- 4. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
4
本ハンズオンの⽬目的
Amazon DynamoDB のテーブル作成およびデータ操作を体験する
• 本オンラインセミナーは、AWS マネジメントコンソールを使って Amazon
DynamoDB テーブルを作成し、アプリケーションからのアクセスを体験するハ
ンズオンとなります
• AWS クラウド無料料利利⽤用枠の範囲で確認できます
https://aws.amazon.com/jp/free/
- 5. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
5
事前に準備すべきもの
AWS アカウント
• AWS アカウント作成の流流れとポイント
https://aws.amazon.com/jp/register-‐‑‒flow/
Web ブラウザ
• Firefox または Chrome を推奨
関連資料料のダウンロード(画⾯面右上にリンクあり)
• http://bit.ly/2pgYSwn (テーブル登録⽤用データ)
• http://bit.ly/2p0u96e (簡易易アプリケーションデータ)
資料料を選択して
参照をクリック
- 6. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
6
注意事項
お客様の環境により、本ラボが実施できない場合がございます
• すべてのサポートは難しい点についてご了了承ください
本資料料からコピーアンドペーストしないでください
• 不不必要なスペース等が⼊入る可能性があります
複数の画⾯面を表⽰示するため、ディスプレイ表⽰示を⼯工夫してください
オンラインセミナー
配信画⾯面
ブラウザ(Chrome, Firefox)
・資料料(PDF)閲覧
・AWS マネジメントコンソール
・簡易易アプリケーション
・⼊入⼒力力⽤用テキスト
など 任意のテキストエディタ
・コピーアンドペースト⽤用に使⽤用
- 7. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
7
Agenda
• Amazon DynamoDB 概要
• ハンズオン
• マネジメントコンソールを使⽤用した操作
• AWS SDK を使⽤用した操作
• ハンズオンで使⽤用したリソースの削除
※ 「ハンズオン」ページが皆様が作業するページです
- 8. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
8
Amazon DynamoDB 概要
- 9. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
9
AWS が提供するデータベースサービス
Amazon RDS Amazon DynamoDB
Amazon ElastiCache Amazon Redshift
リレーショナルデータベース
Aurora, PostgreSQL, MySQL,
MariaDB, Oracle, SQL Server
⾼高速でシームレスな拡張性と信頼性を持つ
NoSQL データベース
インメモリキャッシュ
Memcached, Redis
ペタバイト規模のデータウェアハウス
- 10. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
10
Amazon DynamoDB の特徴
• ⾼高速、安定したパフォーマンス
• ⾼高いスケーラビリティ
• 完全マネージド型
• イベントドリブンプログラミング
• きめ細かなアクセス制御
• 柔軟性
参考資料料:
Amazon DynamoDB : https://aws.amazon.com/jp/dynamodb/
Amazon DynamoDB ドキュメント: https://aws.amazon.com/jp/documentation/dynamodb/
クラウドサービス活⽤用資料料集: https://aws.amazon.com/jp/aws-‐‑‒jp-‐‑‒introduction/
Amazon が提供する⾼高い信頼性、スケーラビリティ、低レイテンシで
安定した性能を兼ね備えた NoSQL データベースサービス
- 11. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
11
Ad Tech
• リアルタイム⼊入札
プラットフォーム
• レコメンデーション
エンジン
ゲーム
• プレイヤーのステータス、
ハイスコア
IoT
• デバイスデータの保存
• Amazon DynamoDB を
Amazon Redshift デー
タウェアハウスに接続し、
BI 分析を実施
Amazon DynamoDB の使いドコロ
- 12. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
12
テーブル設計
テーブル
項⽬目
(items)
属性
(attributes)
パーティションキー
(必須)
ソートキー
(オプション)
スキーマなし
1:Nモデルのリレーションシップ
豊富なQueryをサポート
同じパーティションキー内でソート
キーバリュー型のアクセスを実現
パーティショニングに利利⽤用される
==, <, >, >=,<=
“begins with”
“between”
sorted results
counts
先頭/末尾 N件
ページ単位出⼒力力
パーティションキー + ソートキー(オプション) = プライマリキー
- 13. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
13
API
コントロールプレーン
CreateTable 新しいテーブルを作成する
DescribeTable プライマリキーのスキーマなどテー
ブルに関する情報を返す
ListTables テーブル名をすべて返す
UpdateTable テーブル・インデックスを設定変更更、新しいイン
デックスを作成または削除、DynamoDBストリー
ムを設定変更更する
DeleteTable テーブルとすべての依存オブジェク
トを削除する
データプレーン
PutItem テーブルに単⼀一の項⽬目を書き込む
BatchWriteItem 最⼤大25個の項⽬目をテーブルに書き込む。
複数のテーブルから複数の項⽬目を削除
することもできる
GetItem テーブルから単⼀一の項⽬目を取り出す。
項⽬目全体または属性のサブセットのみ
取り出すことができる
BatchGetItem 1つ以上のテーブルから最⼤大100個の項
⽬目を取り出す
Query プライマリキーの属性値を使⽤用して
テーブルまたはセカンダリインデック
スの項⽬目を検索索
Scan 指定されたテーブルまたはインデック
スのすべての項⽬目を取り出す
UpdateItem 項⽬目の1つ以上の属性を変更更する
DeleteItem テーブルから単⼀一の項⽬目を削除する
DynamoDB ストリーム
ListStreams すべて、または特定のテーブルのス
トリームを返す
DescribeStream ストリームに関する情報を返す
GetShardIterator シャードイテレーターを返す
GetRecords 特定のシャードイテレーターを使⽤用
して1つ以上のストリームレコードを
返す
- 14. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
14
操作例例 GetItem (AWS CLI を使⽤用)
aws dynamodb get-‐‑‒item -‐‑‒-‐‑‒table-‐‑‒name ServiceList -‐‑‒-‐‑‒key
'{"Category":{"S":"Computing"}, "ServiceName":{"S":"Amazon EC2"}}'
Category:
Computing
ServiceName:
Amazon EC2
ShortDescription:
Secure and resizable compute capacity in the cloud
テーブル: ServiceList
パーティションキー ソートキー
{"Item": {"Category": {"S": "Computing"}, "ServiceName": {"S":
"Amazon EC2"}, "ShortDescription": {”S": "Secure and resizable compute
capacity in the cloud"}}}
項⽬目(item)
- 15. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
15
ハンズオン
-‐‑‒マネジメントコンソールを使⽤用した操作 -‐‑‒
- 16. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
16
作業概要
マネジメントコンソールから以下作業を⾏行行う
• テーブル作成
• 項⽬目追加
• クエリ
- 17. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
17
AWS マネジメントコンソールへサインイン
作業: 事前に準備した AWS アカウントへサインイン
- 18. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
18
AWS マネジメントコンソールへサインイン (続き)
作業: ⾔言語設定を⽇日本語にする
画⾯面左下をクリック
- 19. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
19
AWS マネジメントコンソールへサインイン (続き)
作業: 使⽤用するリージョンを選択する
画⾯面右上をクリック
特に理理由がなければ
「東京」リージョンを
選択してください
- 20. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
20
進捗確認
AWS マネジメントコンソールへサインインできましたか?
作業が終わった⽅方は左上の
マークをクリックし、[賛
成] を選択してください
確認が終わりましたら、
[状態の消去] で状態を
キャンセルできます
(お時間が余った⽅方)参考資料料:
Amazon DynamoDB : https://aws.amazon.com/jp/dynamodb/
Amazon DynamoDB ドキュメント: https://aws.amazon.com/jp/documentation/dynamodb/
クラウドサービス活⽤用資料料集: https://aws.amazon.com/jp/aws-‐‑‒jp-‐‑‒introduction/
- 21. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
21
テーブル作成
作業: サンプルデータを登録するための「Pictures」テーブルおよび「セカ
ンダリインデックス」を作成する
Pictures:
例例:
ローカルセカンダリインデックス:
パーティションキー ソートキー
Uehara 2017-04-06
10:15:00
./images/101
4.jpg
0
ユーザー名 ⽇日付 写真データの
パス
カウント情報
(⼈人気投票)
UName Date Path TotalCount
パーティションキー ソートキー
UName TotalCount Path Date
- 22. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
22
DynamoDB コンソールへ移動
1. 画⾯面左上 [サービス] を
クリック 2. [DynamoDB] を検索索、
クリック
- 23. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
23
DynamoDB コンソールへ移動
[テーブルの作成] をクリック
※はじめてテーブルを作成する場合
[テーブルの作成] をクリック
※すでにいくつかのテーブルがある場合
- 24. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
24
テーブル作成(続き)
作業: サンプルデータを登録するための「Pictures」テーブルを作成する
1. テーブル名
[Pictures]
2. プライマリキー
パーティションキー:
UName [⽂文字列列]
ソートキーの追加を
チェック:
Date [⽂文字列列]
3. [デフォルト設定の使⽤用]
チェックを外す
注意!
⼤大⽂文字/⼩小⽂文字
を正しく⼊入⼒力力し
てください
- 25. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
25
テーブル作成(続き)
作業: インデックスを追加する
1. [インデックスの追加]
をクリック
2. プライマリキー
パーティションキー:
UName [⽂文字列列]
ソートキーの追加を
クリック:
TotalCount [数値]
3. [ローカル…] をチェック
4. [インデックスの追加] をクリック
注意!
⼤大⽂文字/⼩小⽂文字
を正しく⼊入⼒力力し
てください
- 26. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
26
テーブル作成(続き)
作業: サンプルデータを登録するための「Pictures」テーブルを作成する
[作成] をクリック
- 27. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
27
テーブル作成(続き)
作業: サンプルデータを登録するための「Pictures」テーブルを作成する
最新状況を確認するためには、
ブラウザのリロードを⾏行行って
ください
- 28. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
28
テーブル作成(続き)
作業: 作成したリソースの確認
Pictures というテーブルが
存在することを確認
[インデックス]タブで
インデックスが作成さ
れているのを確認
- 29. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
29
進捗確認
Pictures テーブル、ローカルセカンダリインデックスが作成できました
か?
作業が終わった⽅方は左上の
マークをクリックし、[賛
成] を選択してください
確認が終わりましたら、
[状態の消去] で状態を
キャンセルできます
(お時間が余った⽅方)参考資料料:
Amazon DynamoDB : https://aws.amazon.com/jp/dynamodb/
Amazon DynamoDB ドキュメント: https://aws.amazon.com/jp/documentation/dynamodb/
クラウドサービス活⽤用資料料集: https://aws.amazon.com/jp/aws-‐‑‒jp-‐‑‒introduction/
- 30. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
30
項⽬目追加
作業: 項⽬目の作成をクリック
2. [項⽬目の作成] をクリック
1. [項⽬目] タブをクリック
- 31. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
31
項⽬目追加(続き)
作業: UName、Date、TotalCount を⼊入⼒力力
UName: Uehara
Date: 2017-‐‑‒04-‐‑‒25 09:00:23
TotalCount: 0
- 32. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
32
項⽬目追加(続き)
作業: + をクリックし String を選択後、Path を追加
2. [String] を選択
3. FIELD: Path
VALUE: ./images/1904.jpg
4. [保存] をクリック
1. +をクリック
- 33. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
33
項⽬目追加(続き)
作業: 1 項⽬目がテーブルに書き込まれたことを確認
- 34. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
34
項⽬目追加(続き)
作業: Text 形式でデータを書き込むため、以下ファイルをダウンロード
http://bit.ly/2pgYSwn (テーブル登録⽤用データ)
1項⽬目分のデータ
- 35. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
35
項⽬目追加(続き)
作業: 項⽬目の作成 -‐‑‒ Text 形式を選択
1. [項⽬目の作成] を
クリック
2. [Text] を
クリック
- 36. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
36
項⽬目追加(続き)
作業: DynamoDB JSON を選択後、内容を⼀一旦削除
1. [DynamoDB
JSON] をチェック*
2. 内容を削除
*この処理理を忘れた場合、P37で保存をク
リックしたときに以下のようなエラーが出
ます
One or more parameter values were invalid: Type
mismatch for key UName expected: S actual: M (Service:
AmazonDynamoDBv2; Status Code: 400; Error Code:
ValidationException; Request ID: ….
- 37. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
37
項⽬目追加(続き)
作業: http://bit.ly/2pgYSwn から1項⽬目⽬目のデータをコピー
1. 1項⽬目⽬目のデータ
をコピー&ペースト
2. [保存]をクリック
3. 同様の作業を⾏行行い、
残りの3項⽬目も書き
込みます
- 38. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
38
項⽬目追加(続き)
作業: 全部で5項⽬目存在することを確認
- 39. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
39
進捗確認
5つの項⽬目が書き込まれていますか?
作業が終わった⽅方は左上
のマークをクリックし、
[賛成] を選択してくださ
い
確認が終わりましたら、
[状態の消去] で状態を
キャンセルできます
(時間が余った⽅方)参考資料料:
Amazon DynamoDB : https://aws.amazon.com/jp/dynamodb/
Amazon DynamoDB ドキュメント: https://aws.amazon.com/jp/documentation/dynamodb/
クラウドサービス活⽤用資料料集: https://aws.amazon.com/jp/aws-‐‑‒jp-‐‑‒introduction/
- 40. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
40
クエリ
作業: スキャン 指定されたテーブルまたはインデックスのすべての項⽬目を取り出す
1. [スキャン][Pictures]テーブ
ルを選択し、[開始]をクリック
2. すべての項⽬目が表⽰示されてい
ることを確認
- 41. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
41
クエリ(続き)
作業: クエリ プライマリキーを使⽤用して項⽬目を検索索
2. [開始]を
クリック
1. [クエリ][Pictures]テーブルを選択
パーティションキー: Uehara
Date の昇順でソート
- 42. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
42
クエリ(続き)
作業: セカンダリインデックス
を使⽤用したクエリ
2. [開始]をクリック
1. [クエリ][UName-‐‑‒TotalCount-‐‑‒index]
索索引を選択
パーティションキー: Uehara
ソートキー: >= 10
- 43. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
43
進捗確認
マネジメントコンソールを使⽤用したクエリが確認できましたか ?
作業が終わった⽅方は左上の
マークをクリックし、[賛
成] を選択してください
確認が終わりましたら、
[状態の消去] で状態を
キャンセルできます
(時間が余った⽅方)参考資料料:
Amazon DynamoDB : https://aws.amazon.com/jp/dynamodb/
Amazon DynamoDB ドキュメント: https://aws.amazon.com/jp/documentation/dynamodb/
クラウドサービス活⽤用資料料集: https://aws.amazon.com/jp/aws-‐‑‒jp-‐‑‒introduction/
- 44. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
44
ハンズオン
-‐‑‒ AWS SDK を使⽤用した操作 -‐‑‒
- 45. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
45
操作概要
• IAM ユーザーおよびアクセスキーを作成
• AWS SDK を使⽤用した操作 1
• ListTables、PutItem、GetItem、UpdateItem、DeleteItem
• AWS SDK を使⽤用した操作 2
• ListTables 、Query、UpdateItem
- 46. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
46
AWS SDKs and CLI
各種⾔言語むけのオフィシャル SDK や CLI を利利⽤用
Java Python PHP .NET Ruby nodeJS
iOS Android
Javascript
in the Browser AWS CLI
- 47. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
47
IAM ユーザーとアクセスキーを作成
1. 画⾯面左上 [サービス] を
クリック
2. [IAM] を検索索、クリック
- 48. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
48
IAM ユーザーとアクセスキーを作成 (続き)
2. [ユーザーを追加] をク
リック
1. [ユーザー] をクリック
- 49. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
49
IAM ユーザーとアクセスキーを作成 (続き)
1. ユーザー名:
demouser
2. [プログラムによる
アクセス] をチェック 3. [次のステップ: アク
セス権限] をクリック
- 50. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
50
IAM ユーザーとアクセスキーを作成 (続き)
1. [既存のポリシーを直接
アタッチ] をクリック
3. [AmazonDynamoDBFullAccess]
をチェック
2. [Dynamo] を検索索
- 51. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
51
IAM ユーザーとアクセスキーを作成 (続き)
画⾯面右下 [次のステッ
プ: 確認] をクリック
- 52. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
52
IAM ユーザーとアクセスキーを作成 (続き)
[ユーザーの作成] をク
リック
- 53. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
53
IAM ユーザーとアクセスキーを作成 (続き)
1. [表⽰示] を
クリック
2. [アクセスキーID] [シークレットア
クセスキー] の値をメモ
- 54. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
54
IAM ユーザーとアクセスキーを作成 (続き)
[閉じる] を
クリック
- 55. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
55
IAM ユーザーとアクセスキーを作成 (続き)
この後の処理理のため、
DynamoDB コンソールに戻る
[demouser] が表⽰示されており、アクセ
スキーが有効になっていることを確認
- 56. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
56
進捗確認
アクセスキーの作成が完了了しましたか?
作業が終わった⽅方は左上の
マークをクリックし、[賛
成] を選択してください
確認が終わりましたら、
[状態の消去] で状態を
キャンセルできます
(時間が余った⽅方)参考資料料:
Amazon DynamoDB : https://aws.amazon.com/jp/dynamodb/
Amazon DynamoDB ドキュメント: https://aws.amazon.com/jp/documentation/dynamodb/
クラウドサービス活⽤用資料料集: https://aws.amazon.com/jp/aws-‐‑‒jp-‐‑‒introduction/
- 57. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
57
ハンズオン -‐‑‒ AWS SDK を使⽤用した操作 1
ListTables、PutItem、GetItem、
UpdateItem、DeleteItem
- 58. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
58
資料料ダウンロード
作業: ラボ⽤用の簡易易アプリケーションをダウンロードし、Zipを展開
http://bit.ly/2p0u96e
ファイル構成
DynamoDBDemo/
-‐‑‒ demo1.html ← AWS SDK を使⽤用した操作 1 で使⽤用
-‐‑‒ demo2.html ← AWS SDK を使⽤用した操作 2 で使⽤用
-‐‑‒ js/ ← JavaScriptファイルを格納
-‐‑‒ images/ ← サンプル写真データを格納
※ これらのファイルは本ハンズオン以外で使⽤用しないでください
- 59. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
59
demo1.html を表⽰示
作業: demo1.html をクリック(ブラウザで表⽰示)
- 60. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
60
アクセスキーのセット
1. 前の⼿手順でコピーした [アクセ
スキーID] [シークレットアクセ
スキー] をペースト
2. [Continue] をクリック
- 61. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
61
ListTables リストのすべてのテーブル名を返す
作業: ListTables を使⽤用してテーブルリストを表⽰示し、利利⽤用するテーブル
を選択する
1. [Region] Tokyoを選択
2. [DynamoDB Table
Name] Pictures を選択
3. [Next] をクリック
- 62. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
62
ListTables リストのすべてのテーブル名を返す
実装例例: ListTables を使⽤用してテーブルリストを表⽰示し、利利⽤用するテーブ
ルを選択する
dynamodb.listTables({}, function(err, data) {
if (err) {
console.log("Identity Key or Secret Key is invalid!");
省省略略
return;
}
else {
省省略略
if(data.TableNames.length > 0) {
var html = "<optgroup label='DynamoDB Table'>";
for(var n = 0; n < data.TableNames.length; n++) {
html += "<option value='" + data.TableNames[n] + "'>" + data.TableNames[n] + "</option>";
}
html += "</optgroup>";
省省略略
}
}
});
- 63. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
63
PutItem テーブルに単⼀一の項⽬目を書き込む
2. [User Name]
任意の名前を⼊入⼒力力
3. [Date] ⾃自動で現在の時間
が⼊入⼒力力済みとなります
後でこの値を使⽤用しますので、
コピーしておいてください
4. [Path] 以下を⼊入⼒力力
./images/3188.jpg 5. [Submit]
をクリック
6. DynamoDB コン
ソールでも確認してみ
てください
1. [Put an Item] をクリック
- 64. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
64
PutItem テーブルに単⼀一の項⽬目を書き込む
実装例例:
var params = {
Item: {
"UName": {
S: putUserName
},
"Date": {
S: putDate
},
"Path": {
S: putPath
},
"TotalCount" : {
N: putCount
}
},
ReturnConsumedCapacity: "TOTAL",
TableName: tableName
};
省省略略
dynamodb.putItem(params, function(err, data) {
省省略略
今回TotalCountには、別
の箇所で 0 が⾃自動で⼊入⼒力力
されるようにしています
- 65. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
65
GetItem テーブルから単⼀一の項⽬目を取り出す
2. [User
Name] 先ほど
⼊入⼒力力した名前
1. [Get an Item] を
クリック
3. [Date] 先ほど
コピーした値を
ペースト
4. [Submit]
をクリック
5. 表⽰示された
情報を確認
- 66. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
66
GetItem テーブルから単⼀一の項⽬目を取り出す
実装例例:
var params = {
Key: {
"UName": {
S: getUserName
},
"Date": {
S: getDate
}
},
TableName: tableName
};
省省略略
dynamodb.getItem(params, function(err, data) {
省省略略
- 67. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
67
UpdateItem 項⽬目の1つ以上の属性を変更更する
2. [User
Name] 先ほど
⼊入⼒力力した名前を
⼊入れてください
1. [Update an
Item] をクリック
3. [Show Info] をク
リック
- 68. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
68
UpdateItem 項⽬目の1つ以上の属性を変更更する
1. 上に表⽰示された
情報を元に、[User
Name]、[Date]
をペースト
2. [Path]
./images/3648.jpg
※内容をUpdateする※Total Count は変
更更しないため空欄
3. [Submit]
をクリック
- 69. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
69
UpdateItem 項⽬目の1つ以上の属性を変更更する
実装例例:
var params = {
ExpressionAttributeValues: {
":v1": {
S: userName
}
},
KeyConditionExpression: "UName = :v1",
Select : "ALL_̲ATTRIBUTES",
TableName: tableName
};
省省略略
dynamodb.query(params,function(err,data){
省省略略
params = {
ExpressionAttributeNames: {
"#PH": "Path"
},
ExpressionAttributeValues: {
":p": {
S: updatePath
}
},
Key: {
"UName": {
S: updateUserName
},
"Date": {
S: updateDate
}
},
ReturnValues: "ALL_̲NEW",
TableName: tableName,
UpdateExpression: "SET #PH = :p"
};
省省略略
dynamodb.updateItem(params, function(err, data) {
省省略略
1. 最初にQueryを実⾏行行
2. PathをUpdateする場
合
- 70. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
70
DeleteItem テーブルから単⼀一の項⽬目を削除する
2. [User Name] 先
ほど⼊入⼒力力した名前を
⼊入れてください
1. [Delete an Item]
をクリック
3. [Date] 先ほどコ
ピーした値をペース
トしてください
4. [Submit]
をクリック
5. DynamoDB コン
ソールでも確認してみ
てください
Delete An Item
- 71. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
71
DeleteItem テーブルから単⼀一の項⽬目を削除する
実装例例:
var params = {
Key: {
"UName": {
S: delUserName
},
"Date": {
S: delDate
}
},
TableName: tableName
};
省省略略
dynamodb.deleteItem(params, function(err, data) {
省省略略
- 72. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
72
進捗確認
ここまでの処理理が完了了しましたか?
作業が終わった⽅方は左上の
マークをクリックし、[賛
成] を選択してください
確認が終わりましたら、
[状態の消去] で状態を
キャンセルできます
(時間が余った⽅方)参考資料料:
Amazon DynamoDB : https://aws.amazon.com/jp/dynamodb/
Amazon DynamoDB ドキュメント: https://aws.amazon.com/jp/documentation/dynamodb/
クラウドサービス活⽤用資料料集: https://aws.amazon.com/jp/aws-‐‑‒jp-‐‑‒introduction/
- 73. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
73
ハンズオン -‐‑‒ AWS SDK を使⽤用した操作 2
Query、UpdateItem
- 74. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
74
demo2.html を表⽰示
作業: demo2.html をクリック(ブラウザで表⽰示)
- 75. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
75
アクセスキーのセット
1. 前の⼿手順でコピーした [アクセ
スキーID] [シークレットアクセ
スキー] をペースト
2. [Continue] をクリック
- 76. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
76
ListTables リストのすべてのテーブル名を返す
作業: ListTables を使⽤用してテーブルリストを表⽰示し、利利⽤用するテーブル
を選択する
1. [Region] Tokyoを選択
2. [DynamoDB Table
Name] Pictures を選択
3. [Next] をクリック
- 77. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
77
Query プライマリキーを使⽤用して項⽬目を検索索
作業: Query を使⽤用してユーザーに紐紐付く写真を表⽰示する
1. [User Name] Uehara
2. [Show Pictures]
をクリック
3. 写真が表⽰示される
のを確認する
- 78. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
78
UName Date Path Total
Count
Ohba 2017-‐‑‒04-‐‑‒25
09:00:23
./images/9618.jpg 0
Ohba 2017-‐‑‒04-‐‑‒26
15:12:30
./images/5151.jpg 0
Uehara 2017-‐‑‒04-‐‑‒25
09:00:23
./images/1904.jpg 0
Uehara 2017-‐‑‒04-‐‑‒25
10:11:11
./images/2032.jpg 10
Uehara 2017-‐‑‒04-‐‑‒26
12:55:25
./images/2448.jpg 2
Query プライマリキーを使⽤用して項⽬目を検索索
実装例例: Query を使⽤用してユーザーに紐紐付く写真を抽出する
この処理理で指定したUNameの項⽬目を読み込み、
Pathを使⽤用して写真を表⽰示している
var params = {
ExpressionAttributeValues: {
":v1": {
S: userName
}
},
KeyConditionExpression: "UName = :v1",
Select : "ALL_ATTRIBUTES",
TableName: tableName
};;
dynamodb.query(params,function(err,data){
- 79. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
79
UdateItem 項⽬目の1つ以上の属性を変更更する
作業: UpdateItem を使⽤用して TotalCount 属性に 1 を追加する
好きな写真を何度度かクリッ
クしてください
- 80. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
80
UdateItem 項⽬目の1つ以上の属性を変更更する
実装例例: UpdateItem を使⽤用して TotalCount 属性に 1 を追加する
UName Date Path Total
Count
Ohba 2017-‐‑‒04-‐‑‒25
09:00:23
./images/9618.jpg 0
Ohba 2017-‐‑‒04-‐‑‒26
15:12:30
./images/5151.jpg 0
Uehara 2017-‐‑‒04-‐‑‒25
09:00:23
./images/1904.jpg 0
Uehara 2017-‐‑‒04-‐‑‒25
10:11:11
./images/2032.jpg 10
Uehara 2017-‐‑‒04-‐‑‒26
12:55:25
./images/2448.jpg 2
var params = {
ExpressionAttributeNames: {
"#CT": "TotalCount"
},
ExpressionAttributeValues: {
":c": {
N: "1"
}
},
Key: {
"UName": {
S: userName
},
"Date": {
S: dateId
}
},
ReturnValues: "ALL_NEW",
TableName: tableName,
UpdateExpression: "SET #CT = #CT + :c"
};;
dynamodb.updateItem(params, function(err, data) {
- 81. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
81
Query プライマリキーを使⽤用して項⽬目を検索索
作業: ローカルセカンダリインデックスを使⽤用してランキングを表⽰示する
1. [Best Picture]
をクリック
2. ⼈人気の写真順に並ぶ
ことを確認
- 82. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
82
Query プライマリキーを使⽤用して項⽬目を検索索
実装例例: ローカルセカンダリインデックスを使⽤用してランキングを表⽰示す
る
UName Total
Count
Date Path
Ohba 0 2017-‐‑‒04-‐‑‒25
09:00:23
./images/96
18.jpg
Ohba 0 2017-‐‑‒04-‐‑‒26
15:12:30
./images/51
51.jpg
Uehara 10 2017-‐‑‒04-‐‑‒25
10:11:11
./images/20
32.jpg
Uehara 2 2017-‐‑‒04-‐‑‒26
12:55:25
./images/24
48.jpg
Uehara 0 2017-‐‑‒04-‐‑‒25
09:00:23
./images/19
04.jpg
var params = {
ExpressionAttributeValues: {
":v1": {
S: userName
}
},
KeyConditionExpression: "UName = :v1",
ScanIndexForward : false,
IndexName: "UName-‐‑‒TotalCount-‐‑‒index",
Select : "ALL_̲ATTRIBUTES",
TableName: tableName
};
省省略略
dynamodb.query(params,function(err,data){
- 83. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
83
進捗確認
ここまでの処理理が確認できましたか ?
作業が終わった⽅方は左上の
マークをクリックし、[賛
成] を選択してください
確認が終わりましたら、
[状態の消去] で状態を
キャンセルできます
(時間が余った⽅方)参考資料料:
Amazon DynamoDB : https://aws.amazon.com/jp/dynamodb/
Amazon DynamoDB ドキュメント: https://aws.amazon.com/jp/documentation/dynamodb/
クラウドサービス活⽤用資料料集: https://aws.amazon.com/jp/aws-‐‑‒jp-‐‑‒introduction/
- 84. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
84
ハンズオン -‐‑‒ 環境の削除 -‐‑‒
- 85. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
85
Amazon DynamoDB テーブルの削除
作業: 作成した「Pictures」テーブルを削除する
1. DynamoDBコンソール
[テーブル] をクリック
3. [アクション][テーブルの削除]
をクリック
4. [削除] をクリック
2. Pictures
テーブルを選択
- 86. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
86
IAM ユーザーの削除
作業: 作成した IAM ユーザー「demouser」を削除する
1. IAM コンソールへ移動
2. ユーザーをクリック 3. demouser をチェック
4. [ユーザーの削除]を
クリック
- 87. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
87
IAM ユーザーの削除(続き)
作業: 作成した IAM ユーザー「demouser」を削除する
1. このメッセージが表⽰示さ
れた場合はチェック
2. [はい、削
除します] を
クリック
- 88. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
88
お疲れ様でした!
以上でハンズオンは終了了となります
- 89. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
89
オンラインセミナー資料料の配置場所
• AWS クラウドサービス活⽤用資料料集
http://aws.amazon.com/jp/aws-‐‑‒jp-‐‑‒introduction/
• AWS Solutions Architect ブログ
最新の情報、セミナー中のQ&A等が掲載されています
http://aws.typepad.com/sajp/
- 90. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
90
公式 Twitter / Facebook
AWS の最新情報をお届けします
@awscloud_̲jp
検索索
最新技術情報、イベント情報、お役⽴立立ち情報、
お得なキャンペーン情報などを⽇日々更更新しています!
もしくは
http://on.fb.me/1vR8yWm
- 91. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
91
AWS の導⼊入、お問い合わせのご相談
AWSクラウド導⼊入に関するご質問、お⾒見見積り、資料料請求を
ご希望のお客様は以下のリンクよりお気軽にご相談ください
https://aws.amazon.com/jp/contact-‐‑‒us/aws-‐‑‒sales/
※「AWS 問い合わせ」で検索索してください
- 92. © 2017 Amazon Web Services, Inc. and its affiliates. All rights reserved.
92