Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
CDNの自動割当ドメインをすべて独自ドメインに移行したよ
Search
wind-up-bird
November 28, 2024
35
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CDNの自動割当ドメインをすべて独自ドメインに移行したよ
yabaibuki.dev #3
wind-up-bird
November 28, 2024
Transcript
17 slides
やってやったぜ!技術的負債解消 LT会 CDNの⾃動割当ドメインをすべて独⾃ドメインに移⾏したよ yabaibuki.dev #3 株式会社スタディスト CREグループ 柳楽瑛
⾃⼰紹介 2 名前: 柳楽瑛 (X: @_windupbird_) 所属: 株式会社スタディスト CREグループ 仕事:
Ruby, Rails, AWS, kubernetes, Terraform etc… 趣味: 筋トレ、散歩
Teachme Biz 3 画像や動画中⼼を中⼼としたオンラインマニュアル を作成、共有、管理できるサービスです。 Teachme Biz is 何?
Teachme Biz の全体構成 4 1⃣API: ALB + EKS + Aurora
2⃣CDN: Amazon CloudFront + S3 Teachme Biz は AWS を主に使⽤
Teachme Biz の全体構成 5 1⃣API経由でマニュアル表⽰に必要な情報を取得する https://teachme.jp/api/manual/1 { "title": "TMB:Ctrl +
Vで画像貼り付けする⽅法", "text": "", "image": "https://xxx.cloudfront.net/path/to/image.png", "steps": [ { "id": 1, "title": "操作の動画はこんな感じ", "text": "windowsの標準機能が録画対象になってないのでわかり にくいかも..." }, … ] … } id manual_id url 1 1 https://xxx.cloudfront.net/path/to/image.png 2 1 https://xxx.cloudfront.net/path/to/image2.png 3 2 https://xxx.cloudfront.net/path/to/image3.png images テーブル マニュアル表⽰までの流れ
Teachme Biz の全体構成 6 https://xxx.cloudfront.net/path/to/image.png 1⃣API経由でマニュアル表⽰に必要な情報を取得する 2⃣CDNから画像や動画を取得する マニュアル表⽰までの流れ https://teachme.jp/api/manual/1
Teachme Biz の全体構成 7 1⃣API経由でマニュアル表⽰に必要な情報を取得する 2⃣CDNから画像や動画を取得する 3⃣表⽰ https://teachme.jp/api/manual/1 https://xxx.cloudfront.net/path/to/image.png マニュアル表⽰までの流れ
Amazon CloudFront の⾃動割り当てドメイン 8 Amazon CloudFront のディストリビューションを起動すると特定のドメインが使えるようになる → 例: d111111abcdef8.cloudfront.net
S3と連携しておくと、S3に画像や動画などのファイルをアップロードするだけでアクセス可能 → https://d111111abcdef8.cloudfront.net/path/to/image.png 過去、Teachme Bizではこの⾃動割り当てドメインを使っていた... 負債が⽣まれる背景
技術的な負債 9 1⃣他のCDNサービスへ移⾏できない 2⃣もし間違って消してしまったら戻せない ※他にもあるけど割愛 3⃣ドメインの信頼性 4⃣ユーザーがアクセス制限でホワイトリストを運⽤している
技術的な負債 10 1⃣他のCDNサービスへ移⾏できない →将来CDNを他のクラウドサービスやCDNサービスに移⾏することはありえる。 →その時に cloudfront.net を使ったままだと移⾏ができない。 負債レベル: 低
技術的な負債 11 負債レベル: ⾼ https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-creating-console.html 2⃣もし間違って消してしまったら戻せない 引⽤: CloudFront ドメイン名は⼀意です。 ディストリビューションのドメイン名は
以前のディストリビューションで使⽤されて おらず、今後の別のディストリビューション でも再利⽤されません。
技術的な負債 12 負債レベル: ⾼ 2⃣もし間違って消してしまったら戻せない つまり、、、 もしディストリビューションを削除 してしまうと、同じドメインは取得できない。 https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-creating-console.html
技術的な負債 13 2⃣もし間違って消してしまったら戻せない ディストリビューションを再作成しても、 images テーブルに存在する古いURLを 参照し続けてしまう。(障害の発⽣) ちなみに、動画と画像のテーブルには 合計数千万レコードが存在している。 (障害の⻑期化)
id manual_id url 1 1 https://xxx.cloudfront.net/path/to/image.png 2 1 https://xxx.cloudfront.net/path/to/image2.png 3 2 https://xxx.cloudfront.net/path/to/image3.png images テーブル 負債レベル: ⾼
代替ドメインを利⽤する 対策 14 独⾃ドメインを利⽤してアクセスが可能。 https://docs.aws.amazon.com/ja_jp/AmazonCloudFront/latest/DeveloperGuide/CNAMEs.html
代替ドメインを利⽤する 対策 15 独⾃ドメインを利⽤してアクセスが可能。 例: →データベース上のレコードもすべて独⾃ドメインで書き換える ⽤途 旧(⾃動割り当てドメイン) 新(独⾃ドメインを利⽤) 画像
https://xxx.cloudfront.net/path/to/image.png https://image.teachme.jp/path/to/image.png 動画 https://yyy.cloudfront.net/path/to/video.mov https://video.teachme.jp/path/to/video.mov
まとめ 16 1⃣他のCDNサービスへ移⾏できない → ドメインの向き先を変えることで容易に移⾏が可能になる。 2⃣もし間違って消してしまったら戻せない → Amazon CloudFront を再作成して、新しいディストリビューションにDNSを向け直せばよい。
→ もちろんDB上のレコード書き換えも不要。
https://studist.jp/
More Decks by wind-up-bird
See All by wind-up-bird
いつもみてるよ、エラーもその先も
w1ndupb1rd
0
150
Teachme Biz で利用するドメインを統合して安心安全に静的コンテンツを取得する
w1ndupb1rd
0
190
studist tech talk #1
w1ndupb1rd
1
220
トレタの大規模バックエンドを移行するまでの道のりと舞台裏
w1ndupb1rd
1
130
トレタを支える技術(インフラ編)
w1ndupb1rd
0
120
Featured
See All Featured
What the history of the web can teach us about the future of AI
inesmontani
PRO
3
840
Mobile First: as difficult as doing things right
swwweet
225
10k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
540
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
410
Ethics towards AI in product and experience design
skipperchong
2
470
The Limits of Empathy - UXLibs8
cassininazir
2
800
Utilizing Notion as your number one productivity tool
mfonobong
4
710
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
7.1k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
350
How to make the Groovebox
asonas
2
2.6k