S3手なづけてオレオレバックエンドにしてみた話
荒木靖宏
at 2014/05/30 JAWS-UG 中央線
自己紹介
• 名前
– 荒木 靖宏(twitter: ar1)
• 肩書
– JAWS-UG→AWSへ
– プリンシパルソリューション
アーキテクト
• 好きなAWSサービス
– Amazon Virtual Private
Cloud
– AWS Direct Connect
3
S3でWebサーバ
やらせてますか?
4
CDPカテゴリ
-基本パターン
Snapshot
Stamp
Scale Up
Ondemand Disk
-可用性を高める
Multi-Server
Multi-Datacenter
Floating IP
Deep Health Check
-動的コンテンツを処理
Scale Out
Clone Server
NFS Sharding
NFS Replica
State Sharing
URL Rewriting
Rewrite Proxy
Cache Proxy
-静的コンテンツを処理
Web Storage
Direct Hosting
Private Distribution
Cache Distribution
Rename Distribution
-クラウドへのアップロード
Write Proxy
Storage Index
Direct Object Upload
-リレーショナル・データベース
DB Replication
Read Replica
Inmemory DB Cache
Sharding Write
-バッチ処理
Queuing Chain
Priority Queue
Job Observer
Scheduled Autoscaling
-運用保守
Bootstrap
Cloud DI
Stack Deployment
Server Swapping
Monitoring Integration
Web Storage Archive
-ネットワーキング
OnDemand NAT
Backnet
Functional Firewall
Operational Firewall
Multi Load Balancer
WAF Proxy
CloudHub
こいつです
Direct Hosting パターン
• 利点
– 静的コンテンツへのアクセスをS3に任せ
ることで、Webシステムの可用性と耐久
性を容易に高めることができる
• 問題点
– ftpやrsyncなど、S3以外のアップロード
方法への対応
– 動的ページヘの対応
– ヘッダ情報の制限
6
S3手なづけて
オレオレバックエンド
つくりました
7
メインリージョン
node.js upload
nginx
CloudFront
Auto scaling Group
アップロード元 アップロード元
rsync
S3 COPY between buckets
バックアップ
region
origin server
node.js proxy
8
CDPカテゴリ
-基本パターン
Snapshot
Stamp
Scale Up
Ondemand Disk
-可用性を高める
Multi-Server
Multi-Datacenter
Floating IP
Deep Health Check
-動的コンテンツを処理
Scale Out
Clone Server
NFS Sharding
NFS Replica
State Sharing
URL Rewriting
Rewrite Proxy
Cache Proxy
-静的コンテンツを処理
Web Storage
Direct Hosting
Private Distribution
Cache Distribution
Rename Distribution
-クラウドへのアップロード
Write Proxy
Storage Index
Direct Object Upload
-リレーショナル・データベース
DB Replication
Read Replica
Inmemory DB Cache
Sharding Write
-バッチ処理
Queuing Chain
Priority Queue
Job Observer
Scheduled Autoscaling
-運用保守
Bootstrap
Cloud DI
Stack Deployment
Server Swapping
Monitoring Integration
Web Storage Archive
-ネットワーキング
OnDemand NAT
Backnet
Functional Firewall
Operational Firewall
Multi Load Balancer
WAF Proxy
CloudHub
こいつです
これとも組み合わせ
Write Proxy パターン
• 動作
– https://github.com/armaniacs/n
ode-s3ma
– ファイル変更をinotifyで検出して
S3へアップロードするnodeのコー
ド
– x-amz-meta-XXXXヘッダに情報
追加
– さらにもうひとつ別リージョンの
S3へCOPY
CDPカテゴリ
-基本パターン
Snapshot
Stamp
Scale Up
Ondemand Disk
-可用性を高める
Multi-Server
Multi-Datacenter
Floating IP
Deep Health Check
-動的コンテンツを処理
Scale Out
Clone Server
NFS Sharding
NFS Replica
State Sharing
URL Rewriting
Rewrite Proxy
Cache Proxy
-静的コンテンツを処理
Web Storage
Direct Hosting
Private Distribution
Cache Distribution
Rename Distribution
-クラウドへのアップロード
Write Proxy
Storage Index
Direct Object Upload
-リレーショナル・データベース
DB Replication
Read Replica
Inmemory DB Cache
Sharding Write
-バッチ処理
Queuing Chain
Priority Queue
Job Observer
Scheduled Autoscaling
-運用保守
Bootstrap
Cloud DI
Stack Deployment
Server Swapping
Monitoring Integration
Web Storage Archive
-ネットワーキング
OnDemand NAT
Backnet
Functional Firewall
Operational Firewall
Multi Load Balancer
WAF Proxy
CloudHub
こいつです
これとも組み合わせ
さらに組み合わせ
Cache Proxy パターン
• 動作
– https://github.com/armani
acs/s3-reverse-proxy +
nginx
– x-amz-meta-xxxx に入って
いる値を任意のヘッダとして
追加(上書き)
– localに一定時間キャッシュ
12
メインリージョン
node.js upload
nginx
CloudFront
Auto scaling Group
アップロード
元
アップロード元
rsync
S3 COPY between buckets
バックアップ
region
origin server
node.js proxy
1313
まとめ
Direct Hosting + Write Proxy + Cache Proxyを実装
– https://github.com/armaniacs/node-s3ma
– https://github.com/armaniacs/s3-reverse-proxy
– +S3+ELB+AS+nginx+CloudFront+OpsWorks
Nginxでなんでもカスタマイズ可能
しかもNginxサーバではステート保持いらず
– コンテンツがなくなる心配ない(S3にあるから!)
– ステートはx-amz-meta-*****に書いちゃう

S3をてなづけてオレオレバックエンドにしてみた話

  • 1.
  • 2.
    自己紹介 • 名前 – 荒木靖宏(twitter: ar1) • 肩書 – JAWS-UG→AWSへ – プリンシパルソリューション アーキテクト • 好きなAWSサービス – Amazon Virtual Private Cloud – AWS Direct Connect
  • 3.
  • 4.
    4 CDPカテゴリ -基本パターン Snapshot Stamp Scale Up Ondemand Disk -可用性を高める Multi-Server Multi-Datacenter FloatingIP Deep Health Check -動的コンテンツを処理 Scale Out Clone Server NFS Sharding NFS Replica State Sharing URL Rewriting Rewrite Proxy Cache Proxy -静的コンテンツを処理 Web Storage Direct Hosting Private Distribution Cache Distribution Rename Distribution -クラウドへのアップロード Write Proxy Storage Index Direct Object Upload -リレーショナル・データベース DB Replication Read Replica Inmemory DB Cache Sharding Write -バッチ処理 Queuing Chain Priority Queue Job Observer Scheduled Autoscaling -運用保守 Bootstrap Cloud DI Stack Deployment Server Swapping Monitoring Integration Web Storage Archive -ネットワーキング OnDemand NAT Backnet Functional Firewall Operational Firewall Multi Load Balancer WAF Proxy CloudHub こいつです
  • 5.
    Direct Hosting パターン •利点 – 静的コンテンツへのアクセスをS3に任せ ることで、Webシステムの可用性と耐久 性を容易に高めることができる • 問題点 – ftpやrsyncなど、S3以外のアップロード 方法への対応 – 動的ページヘの対応 – ヘッダ情報の制限
  • 6.
  • 7.
    7 メインリージョン node.js upload nginx CloudFront Auto scalingGroup アップロード元 アップロード元 rsync S3 COPY between buckets バックアップ region origin server node.js proxy
  • 8.
    8 CDPカテゴリ -基本パターン Snapshot Stamp Scale Up Ondemand Disk -可用性を高める Multi-Server Multi-Datacenter FloatingIP Deep Health Check -動的コンテンツを処理 Scale Out Clone Server NFS Sharding NFS Replica State Sharing URL Rewriting Rewrite Proxy Cache Proxy -静的コンテンツを処理 Web Storage Direct Hosting Private Distribution Cache Distribution Rename Distribution -クラウドへのアップロード Write Proxy Storage Index Direct Object Upload -リレーショナル・データベース DB Replication Read Replica Inmemory DB Cache Sharding Write -バッチ処理 Queuing Chain Priority Queue Job Observer Scheduled Autoscaling -運用保守 Bootstrap Cloud DI Stack Deployment Server Swapping Monitoring Integration Web Storage Archive -ネットワーキング OnDemand NAT Backnet Functional Firewall Operational Firewall Multi Load Balancer WAF Proxy CloudHub こいつです これとも組み合わせ
  • 9.
    Write Proxy パターン •動作 – https://github.com/armaniacs/n ode-s3ma – ファイル変更をinotifyで検出して S3へアップロードするnodeのコー ド – x-amz-meta-XXXXヘッダに情報 追加 – さらにもうひとつ別リージョンの S3へCOPY
  • 10.
    CDPカテゴリ -基本パターン Snapshot Stamp Scale Up Ondemand Disk -可用性を高める Multi-Server Multi-Datacenter FloatingIP Deep Health Check -動的コンテンツを処理 Scale Out Clone Server NFS Sharding NFS Replica State Sharing URL Rewriting Rewrite Proxy Cache Proxy -静的コンテンツを処理 Web Storage Direct Hosting Private Distribution Cache Distribution Rename Distribution -クラウドへのアップロード Write Proxy Storage Index Direct Object Upload -リレーショナル・データベース DB Replication Read Replica Inmemory DB Cache Sharding Write -バッチ処理 Queuing Chain Priority Queue Job Observer Scheduled Autoscaling -運用保守 Bootstrap Cloud DI Stack Deployment Server Swapping Monitoring Integration Web Storage Archive -ネットワーキング OnDemand NAT Backnet Functional Firewall Operational Firewall Multi Load Balancer WAF Proxy CloudHub こいつです これとも組み合わせ さらに組み合わせ
  • 11.
    Cache Proxy パターン •動作 – https://github.com/armani acs/s3-reverse-proxy + nginx – x-amz-meta-xxxx に入って いる値を任意のヘッダとして 追加(上書き) – localに一定時間キャッシュ
  • 12.
    12 メインリージョン node.js upload nginx CloudFront Auto scalingGroup アップロード 元 アップロード元 rsync S3 COPY between buckets バックアップ region origin server node.js proxy
  • 13.
    1313 まとめ Direct Hosting +Write Proxy + Cache Proxyを実装 – https://github.com/armaniacs/node-s3ma – https://github.com/armaniacs/s3-reverse-proxy – +S3+ELB+AS+nginx+CloudFront+OpsWorks Nginxでなんでもカスタマイズ可能 しかもNginxサーバではステート保持いらず – コンテンツがなくなる心配ない(S3にあるから!) – ステートはx-amz-meta-*****に書いちゃう

Editor's Notes

  • #8 http://calculator.s3.amazonaws.com/index.html#key=calc-3320C69C-4961-415D-A727-0FBEEAF72E93
  • #13 http://calculator.s3.amazonaws.com/index.html#key=calc-3320C69C-4961-415D-A727-0FBEEAF72E93