Serverless backendformobilegame and_aws-appsync_gamingtechnight-2
-
Upload
amazon-web-services-japan -
Category
Technology
-
view
934 -
download
0
Transcript of Serverless backendformobilegame and_aws-appsync_gamingtechnight-2
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon Web Services Japan K.K.Solutions Architect Fumihiko Hata2017.01.24
AWS におけるモバイルゲーム向けAPI サーバの実装 2018AWS Gaming Tech Night #2
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
内容についての注意点
本資料では2017年1⽉24⽇時点のサービス内容および価格についてご説明しています。最新の情報はAWS公式ウェブサイト(http://aws.amazon.com)にてご確認ください。
• 資料作成には⼗分注意しておりますが、資料内の価格とAWS公式ウェブサイト記載の価格に相違があった場合、AWS公式ウェブサイトの価格を優先とさせていただきます。
• 価格は税抜表記となっています。⽇本居住者のお客様が東京リージョンを使⽤する場合、別途消費税をご請求させていただきます。
AWS does not offer binding price quotes. AWS pricing is publicly available and is subject to change in accordance with the AWS Customer Agreement available at http://aws.amazon.com/agreement/. Any pricing information included in this document is provided only as an estimate of usage charges for AWS services based on certain information that you have provided. Monthly charges will be based on your actual use of AWS services, and may vary from the estimates provided.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Agenda
モバイルゲームのアーキテクチャと構成要素API サーバ実装/アーキテクチャ
Amazon EC2 & ELB (Typical 3-Tier)Amazon API Gateway & AWS Lambda (Serverless 3-Tier)Amazon Cognito (Serverless 2-Tier)AWS AppSync (Managed GraphQL)
まとめ
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
アーキテクチャ例
S3CloudFront
WAF
Shield
ELB
ElastiCache DynamoDB
RDSEC2 Game Servers
EC2 API Servers
Kinesis S3
Redshift
Athena
QuickSight
CognitoRoute53
分析
配信
ネットワークセキュリティ
API
ゲーム
共通基盤
Client
RDS
プッシュ通知
Pinpoint
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
アーキテクチャ例
S3CloudFront
WAF
Shield
ELB
ElastiCache DynamoDB
RDSEC2 Game Servers
EC2 API Servers
Kinesis S3
Redshift
Athena
QuickSight
CognitoRoute53
分析
配信
ネットワークセキュリティ
API
ゲーム
共通基盤
Client
RDS
プッシュ通知
Pinpoint
① HTTP API を⽤いてログイン
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
アーキテクチャ例
S3CloudFront
WAF
Shield
ELB
ElastiCache DynamoDB
RDSEC2 Game Servers
EC2 API Servers
Kinesis S3
Redshift
Athena
QuickSight
CognitoRoute53
分析
配信
ネットワークセキュリティ
API
ゲーム
共通基盤
Client
RDS
プッシュ通知
Pinpoint
② Game Assets をダウンロード
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
アーキテクチャ例
S3CloudFront
WAF
Shield
ELB
ElastiCache DynamoDB
RDSEC2 Game Servers
EC2 API Servers
Kinesis S3
Redshift
Athena
QuickSight
CognitoRoute53
分析
配信
ネットワークセキュリティ
API
ゲーム
共通基盤
Client
RDS
プッシュ通知
Pinpoint
③ Game Serverのマッチメイク
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
アーキテクチャ例
S3CloudFront
WAF
Shield
ELB
ElastiCache DynamoDB
RDSEC2 Game Servers
EC2 API Servers
Kinesis S3
Redshift
Athena
QuickSight
CognitoRoute53
分析
配信
ネットワークセキュリティ
API
ゲーム
共通基盤
Client
RDS
プッシュ通知
Pinpoint
④ GameServer へ接続してバトル
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
アーキテクチャ例
S3CloudFront
WAF
Shield
ELB
ElastiCache DynamoDB
RDSEC2 Game Servers
EC2 API Servers
Kinesis S3
Redshift
Athena
QuickSight
CognitoRoute53
分析
配信
ネットワークセキュリティ
API
ゲーム
共通基盤
Client
RDS
プッシュ通知
Pinpoint
⑤ HTTP API を⽤いて結果を永続化
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
S3CloudFront
WAF
Shield
ELB
ElastiCache DynamoDB
RDSEC2 Game Servers
EC2 API Servers
Kinesis S3
Redshift
Athena
QuickSight
CognitoRoute53
分析
配信
ネットワークセキュリティ
API
ゲーム
共通基盤
Client
RDS
プッシュ通知
Pinpoint
API サーバ
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
モバイルゲームの API サーバ
• ゲーム内の様々なユーザ操作を処理、保存する
• ログイン、アイテム購⼊、デッキ編成、バトルのマッチング、etc.
• 処理結果は RDB に永続されることが多い
• バトルやステージ内での⼀連のゲームプレイ処理は 専⽤のゲームサーバが受け持つことが多い
• HTTP(S) で RESTful など• 全ユーザで同⼀のエンドポイント
ELB
ElastiCache DynamoDB
EC2 API Servers
API
RDS
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
モバイルゲームの API サーバに求められるもの
1. 可⽤性• 落ちるとゲームが進⾏不可に
2. スケーラビリティ• 全ユーザが単⼀のエンドポイント
3. レスポンス速度• ゲーム体験に直接的に影響
4. コードのメンテナビリティ• ⽇々、機能追加・機能修正• 繰り返されるイベント実装
ELB
ElastiCache DynamoDB
EC2 API Servers
API
RDS
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
1.典型的な3層Webアプリケーション
クライアントはHTTP(S) で Web サーバと通信
サーバサイドはELB + EC2 + RDS
Elastic Load Balancing(以下ELB)
Amazon Elastic Compute Cloud
(以下EC2)
Amazon Relational Database Service
(以下RDS)
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
1.典型的な3層Webアプリケーション
‣ メリット‣ 実績が多く枯れた構成‣ カスタマイズ性が⾼い‣ 場合によっては後述の
サーバレスアーキテクチャよりスケールしやすい
‣ デメリット‣ サーバのスペック、台数
などスケールを意識して設計する必要がある
‣ サーバの運⽤は利⽤者に任されている
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
スーパーマリオラン - 任天堂・DeNA様
https://aws.amazon.com/jp/solutions/case-studies/nintendo-dena/
• 150の国と地域が配信対象• 極めて短い構築期間• 配信開始時にアクセスが集中
しかし、障害はなし(2017年3⽉時点で8000万DL)
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
2.Serverless Architecture
Amazon API Gateway(以下API GW)
AWS Lambda(以下Lambda)
Amazon DynamoDB(以下DynamoDB)
Amazon Cognito(以下Cognito) クライアントアプリは Cognito から
Temporary Credentials を得た後、JSON で Web API と通信
サーバサイドはAPI GW/Lambda/DynamoDBといったマネージドサービスを⽤い、EC2 や ELB を利⽤しない
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
2.Serverless Architecture
‣ メリット‣ クライアント側の実装は従
来とあまり変わらずノウハウを活かせる
‣ サーバの運⽤、スケールはAWS に⼀任できる
‣ Cognito によるセキュアなAPI アクセス制御が可能
‣ コスト効率が⾼い‣ デメリット
‣ カスタマイズ性が低い‣ 運⽤ノウハウが枯れていな
い
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
モンスターハンター エクスプロア - カプコン様
https://aws.amazon.com/jp/solutions/case-studies/capcom/
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
3.2-Tier Architectureクライアントアプリは Cognito からTemporary Credentials を得た後、AWS SDK を通じて各 AWS リソースの API を直接叩く
サーバサイドは各 AWS リソースをセッティングしておくのみ(左図は⼀部の例)
AmazonMobile Analytics
(以下MA)
Lambda
DynamoDB
Cognito
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
3.2-Tier Architecture
‣ メリット‣ インフラの運⽤、スケール
は AWS に⼀任できる‣ 上限値の緩和申請は除く
‣ Cognito によるセキュアなアクセス制御が可能
‣ Web API の設計は不要‣ コスト効率が⾼い
‣ デメリット‣ カスタマイズ性が低い‣ 運⽤ノウハウが枯れていな
い‣ クライアントサイドが各
AWSリソースに依存する
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
アナザーエデン - グリー様
https://aws.amazon.com/jp/solutions/case-studies/gree-ddb/
Amazon DynamoDB を利⽤したオートセーブ機能の実装により、通信待ちストレスのない往年の JRPG を彷彿させるようなシームレスなゲーム体験を実現
• MySQL を排除し、サーバーサイドをシンプルに• DynamoDB Streams でリアルタイムな分析も
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
3.2-Tier Architecture2.Serverless Architecture1.典型的な3層Webアプリケーション 構造
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
3.2-Tier Architecture2.Serverless Architecture1.典型的な3層Webアプリケーション 構造
REST REST REST
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
REST API
DataSource
GET /searchGET /m_searchPOST /tapsGET /tapsGET /taps/:idGET /taps/:id/statusPUT /taps/:id
REST Endpoints
ü 簡単にセットアップü 標準の HTTP 呼び出し
p Joinp 簡略化された「一覧情報」p クエリサポートp 順序付けとページングp 通知
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS re:Invent 2017
Introduced AWS AppSyncCurrently Public Previewhttps://pages.awscloud.com/awsappsyncpreview.html
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Managed GraphQL Service
Alexa skill
Elasticsearch
DynamoDB
/foo
AWS AppSync
Browser
Mobile device
SubscriptionAWS Lambda
Other service
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
GraphQL とは• データ取得のために設計された宣⾔的なクエリ⾔語。• 仕様はオープン• グラフDBとは関係ない(例えば、Neo4j)• NoSQL, Relational, HTTP, etc.
REST APIよくあるデータ取得 GraphQLによるデータ取得/posts/postInfo/postJustTitle/postsByAuthor/postNameStartsWithX/commentsOnPost
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
GraphQL とは
• API ⽤のクエリ⾔語
• クライアント ー サーバ間で共有される強い型付け
• クライアントはサーバのデータを取得、更新、購読する
• クライアントはレスポンスの形式を指定。• クライアント側の欲しいデータを欲しい形式でクエリ可能
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
API のためのクエリ⾔語
1. Queries read data
2. Mutations write data
3. Subscriptions are pushed data in real time
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
GraphQLはどのように動くのか
{"id": "1","name": "Get Milk","priority": "1"
},{ "id": "2",
"name": "Go to gym","priority": "5"
},…
type Query {getTodos: [Todo]
}
type Todo {id: ID!name: Stringdescription: Stringpriority: Intduedate: String
}
query {getTodos {
idnamepriority
}}
データのスキーマを定義 問い合わせ(クエリ) 希望したデータが返却
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS AppSync の特徴
• マネージドの GraphQL サービス とクライアント SDK
• AWS アカウント内のリソースに接続
• GraphQL の Request/Response とデータソース間のマッピングを宣⾔的に記述
• オフラインの処理をビルトイン
• クライアント側とサーバ側の更新コンフリクトをクラウド上で解決
• シンプルかつスケーラブルな リアルタイムのデータ同期
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Resolver Mapping Template
• 「GraphQL Request」を「DynamoDB の API コール」にどう変換するか• 「DynamoDB の Response データ」を「Response Body」にどう変換するか
(※データソースが DynamoDB の場合)
これらは Mapping Template を使ってカスタマイズが可能https://docs.aws.amazon.com/ja_jp/appsync/latest/devguide/resolver-mapping-template-reference-overview.html
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Request Template(1) GraphQL Query
https://docs.aws.amazon.com/ja_jp/appsync/latest/devguide/resolver-mapping-template-reference-overview.html
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Request Template(1) GraphQL Query
(2) Request Template
https://docs.aws.amazon.com/ja_jp/appsync/latest/devguide/resolver-mapping-template-reference-overview.html
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Request Template(1) GraphQL Query
(2) Request Template
(3) Dynamo DB API Call
https://docs.aws.amazon.com/ja_jp/appsync/latest/devguide/resolver-mapping-template-reference-overview.html
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Response Template(1) DynamoDB Result Data
https://docs.aws.amazon.com/ja_jp/appsync/latest/devguide/resolver-mapping-template-reference-overview.html
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Response Template(1) DynamoDB Result Data
(2) Response Template
https://docs.aws.amazon.com/ja_jp/appsync/latest/devguide/resolver-mapping-template-reference-overview.html
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Response Template(1) DynamoDB Result Data
(2) Response Template
(3) Response Data
https://docs.aws.amazon.com/ja_jp/appsync/latest/devguide/resolver-mapping-template-reference-overview.html
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Response Template
(3) Response Data
https://docs.aws.amazon.com/ja_jp/appsync/latest/devguide/resolver-mapping-template-reference-overview.html
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Response Template
(3) Response Data
(4) GraphQL Response
https://docs.aws.amazon.com/ja_jp/appsync/latest/devguide/resolver-mapping-template-reference-overview.html
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Response Template
(3) Response Data
(4) GraphQL Response
※ Response Template は Simple にこうも書ける
https://docs.aws.amazon.com/ja_jp/appsync/latest/devguide/resolver-mapping-template-reference-overview.html
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
料⾦
https://aws.amazon.com/jp/appsync/pricing/
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
料⾦例
https://aws.amazon.com/jp/appsync/pricing/
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS AppSync を使ってデータ駆動のアプリケーションを構築
• 堅牢で、1⽇に何百万件ものイベントを処理できるスケーラブルなストレージ
• 地理空間検索
• モバイルとウェブ両⽅でリアルタイムに更新
• モバイルとウェブのクライアント
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS AppSync の利点
• スケーラブルなマネージドの GraphQL Service
• 単⼀リクエストで複数データソースから複数リソースを取得• クライアントが欲しいデータを過不⾜なく取得
→ リクエスト数の低減によるパフォーマンスの向上
• 強⼒な型システム• GraphQL の⾃⼰記述的な API と、
AppSync の宣⾔的な リゾルバ・マッピング・テンプレート→ API ロジックのメンテナビリティを向上
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS AppSync
Alexa skill
Elasticsearch
DynamoDB
/graphql
AWS AppSync
Browser
Mobile device
SubscriptionAWS Lambda
Other service
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
3. 2-Tier Architecture2. Serverless Architecture1. 典型的な3層Web
アプリケーション 構造
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
3. 2-Tier Architecture2. Serverless Architecture1. 典型的な3層Web
アプリケーション 構造★ Managed
GraphQL Service
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
まとめ
• AWS で実現される多様な API サーバ実装⼿段
• ゲーム特性や開発チームに応じて、選択/組み合わせ
• AWS AppSync による• マネージド GraphQL API Server & Client SDK• リアルタイム処理/ストリーミング処理• 宣⾔的なメンテナブル API ロジック