Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Cloudfront with Rails
Search
haruharuharuby
July 27, 2016
Programming
0
120
Cloudfront with Rails
Using cloudfront with rails.
2016.07.26 JAWS-UG Osaka Study Meeting
haruharuharuby
July 27, 2016
Tweet
Share
More Decks by haruharuharuby
See All by haruharuharuby
Effective AWS Step Functions
haruharuharuby
0
170
JP_Stripes 5th anniversary - Plan migration consideration -
haruharuharuby
0
86
Alexa Warming Up my Live Stream!
haruharuharuby
1
82
AAJUG meetup September
haruharuharuby
0
39
How Voice Technology is Changing Customer Experience from Brain Perspectives
haruharuharuby
0
70
IVSの盛り上げ役にAlexaをつかってみようか
haruharuharuby
0
780
Let's make a blog with live streaming in 10 minutes
haruharuharuby
0
510
Alexa Audio Player @Deep Diving
haruharuharuby
0
280
VoiceLunchJp#02 Share VUI App and reputation
haruharuharuby
1
300
Other Decks in Programming
See All in Programming
Navigation 2 を 3 に移行する(予定)ためにやったこと
yokomii
0
270
テストカバレッジ100%を10年続けて得られた学びと品質
mottyzzz
2
600
Putting The Genie in the Bottle - A Crash Course on running LLMs on Android
iurysza
0
140
How Android Uses Data Structures Behind The Scenes
l2hyunwoo
0
460
OSS開発者という働き方
andpad
5
1.7k
AIでLINEスタンプを作ってみた
eycjur
1
230
知っているようで知らない"rails new"の世界 / The World of "rails new" You Think You Know but Don't
luccafort
PRO
1
160
「手軽で便利」に潜む罠。 Popover API を WCAG 2.2の視点で安全に使うには
taitotnk
0
860
複雑なフォームに立ち向かう Next.js の技術選定
macchiitaka
2
130
アルテニア コンサル/ITエンジニア向け 採用ピッチ資料
altenir
0
110
旅行プランAIエージェント開発の裏側
ippo012
2
910
go test -json そして testing.T.Attr / Kyoto.go #63
utgwkk
3
300
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
[RailsConf 2023] Rails as a piece of cake
palkan
57
5.8k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
13k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
9
810
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.5k
Mobile First: as difficult as doing things right
swwweet
224
9.9k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
The Straight Up "How To Draw Better" Workshop
denniskardys
236
140k
Transcript
Cloudfront with Rails クラウドフロントとRails の ツンデレ な関係 2016.07.26 「AWSのおJAWSな使い方」JAWS-UG大阪&JAWS-UG関西女子会合同企画
自己紹介 TiNm’S( ティムズ )と読みます。 プログラマーです。 Ruby On RailsとAWSが主戦場です。 好きなAWS サービスは、OpsWorks。
花澤香菜ちゃん好き。 JAWS-UG-KOBE 所属。 ポケモンGOはまだやってません。
はじめに...
に をかぶせたら、 Webサービスが動かなくなった 体験談をお話します。 今回は... ※Railsはやったことあるけど、 AWSには構築したことないなあ。な人向けの内容です。
なぜ話したいと思ったか。
Cloudfrontはデプロイに20分くらいかかる。 「ちょっとかえて、デプロイ、20分待つ。」 を繰り返すと、時間だけが取られていく。 もう、Prime Video見るしかなくなる。
Agenda • RailsでCloudfrontを導入する理由 • 転送するhttpメソッドではまる。 • 転送するhttpヘッダではまる。 • Cookieの転送ではまる。 •
クエリストリングの転送ではまる。
RailsでCloudfrontを導入する理由
アセット※のキャッシング Cloudfrontにアセットを設置することで、 js、css、 imageファイルをキャッシュできる。 その昔、アセットは、 asset_sync などのgemを利 用してS3に配置していた。 この方法は現在推奨されていない。 (Heroku
も assets は、CDNに設置することを推 奨) 参考: http://guides.rubyonrails.org/asset_pipeline.html ※ Railsで言うところの静的なファイル群のことで、おもに js、css、画像ファイルがそれに当たる。
HTTPS化 Cloudfrontに証明書を設置して、 HTTPS化する。 サーバーやELBに証明書を入れ込む必要がないので、 Railsの設定を単純化できる。 また、バックエンドを httpにすることで、暗号化、複合化を Rails側で実施する必要がなくなり、パフォーマン ス的にも効果が見込める。 (証明書もACM(AWS
Certificate Manager)を利用すれば、証明書の管理もできて効率的。 )
WAFの導入 悪い人をCloudfrontで弾いてしまう。 SQLインジェクションなどの脆弱性対策も Cloudfrontでやってしまう。
1: 転送するhttpメソッドではまる。
POST, PUTできない (>m<)0 Cloudfrontが受信するHTTPメソッドの デフォルト設定はGET,HEADのみ。 (つまり静的サイト向け ) Rails(に限らずほとんどの Webアプリ)では、 PUT、POST、PATCH、DELETEの許可が必
須。 すべてのHTTPメソッドを許可する。
2: 転送するhttpヘッダではまる。
いつもoriginが返る。
Hostヘッダを転送しておく。 RailsはHostヘッダでResponse先を判断している。 Hostヘッダが転送されない場合、 Railsは、Responseとして”//”(ルート)返却する。 つまり、ELBやEC2インスタンスのアドレス (origin)が返ることになる。
3: cookieの転送ではまる。
ログインできん。 Cloudfrontをかぶせたとたんにログイ ンできない。
Cookieを転送する。 RailsのセッションはデフォルトでCookieを利用する。 Cookieが転送されないとログインもできない。
4: クエリストリングではまる。
検索できん。 検索機能でよくあるURL。 http://example.com/search?q=XXXXXXX originでは効くのに、Cloudfrontをかぶせると 効かなくなる。
クエリストリングを転送する。 Cloudfrontはデフォルトでquerystringを転送しない。 検索機能を提供するransack を利用するならこの設定が必須。
まとめると
• すべてのHTTPメソッドを許可する。 • Hostヘッダを転送する。 • (セッションデフォルトなら)Cookieを転送する。 • (gemによっては)クエリストリングを転送する。
明日は、 Alexa !!!!!!!!!!!!!! そして....
https://www.youtube.com/watch?v=vizNdRTXK90&feature=youtu.be