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
Running App on AppRunner
Search
ohr486
June 27, 2021
Technology
0
810
Running App on AppRunner
2021-06-27
Drecom SRE Sunday
https://drecom.connpass.com/event/213139/
ohr486
June 27, 2021
Tweet
Share
More Decks by ohr486
See All by ohr486
負荷試験Night#1 負荷試験2023年トレンド
ohr486
17
4.8k
Elixir/PhoenixによるWeb開発の現場から
ohr486
1
530
Hacking Phoenix Performance
ohr486
1
360
Plug & WAF
ohr486
2
500
elixirをプロダクションに導入する
ohr486
1
670
IEx maniacs
ohr486
4
620
Hack and Read Elixir
ohr486
2
740
sponsor-talk-drecom-heisei-ruby-kaigi
ohr486
0
850
ex-app-on-k8s
ohr486
0
240
Other Decks in Technology
See All in Technology
物体検出モデルでシイタケの収穫時期を自動判定してみた。 #devio2025
lamaglama39
0
280
「魔法少女まどか☆マギカ Magia Exedra」の多様なバトルの開発を柔軟かつ効率的に実現するためのPure C#とUnityの分離について
gree_tech
PRO
0
290
Databricks AI/BI Genie の「値ディクショナリー」をAmazonの奥地(S3)まで見に行く
kameitomohiro
1
400
CNCFの視点で捉えるPlatform Engineering - 最新動向と展望 / Platform Engineering from the CNCF Perspective
hhiroshell
0
140
AI AgentをLangflowでサクッと作って、1日働かせてみた!
yano13
1
150
AIプロダクトのプロンプト実践テクニック / Practical Techniques for AI Product Prompts
saka2jp
0
100
知覚とデザイン
rinchoku
1
460
AI時代の開発を加速する組織づくり - ブログでは書けなかったリアル
hiro8ma
1
290
CREが作る自己解決サイクルSlackワークフローに組み込んだAIによる社内ヘルプデスク改革 #cre_meetup
bengo4com
0
310
様々なファイルシステム
sat
PRO
0
230
アウトプットから始めるOSSコントリビューション 〜eslint-plugin-vueの場合〜 #vuefes
bengo4com
3
1.6k
Dylib Hijacking on macOS: Dead or Alive?
patrickwardle
0
460
Featured
See All Featured
How GitHub (no longer) Works
holman
315
140k
Building Better People: How to give real-time feedback that sticks.
wjessup
369
20k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
The Invisible Side of Design
smashingmag
302
51k
GitHub's CSS Performance
jonrohan
1032
470k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.5k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.7k
Code Reviewing Like a Champion
maltzj
526
40k
Faster Mobile Websites
deanohume
310
31k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Transcript
Running App on AppRunner 2021-06-27 Drecom SRE Sunday slide:https://docs.google.com/presentation/d/1LpzbfhtwIhHo6t4lzhboy75L6Vj5LYpdlbPwvmmW5ek/edit?usp=sharing demo:https://github.com/ohr486/blog-sample-aws-app-runner
agenda • About Me • Target • Goal • AppRunnerとは
• AppRunnerのアーキテクチャ • Set Up AppRunner • Demo • AppRunnerでできること • AppRunnerでできないこと • AppRunnerに足りないもの • まとめ
About Me • Tsunenori Ohara/おーはら ◦ Twitter: @ohrdev ◦ Github:
ohr486 • Work ◦ Drecom, SRE部 manager ◦ SRE/Infra/Ruby,Elixir,Lisp,etc • Community ◦ tokyo.ex, ElixirConfJapan, Erlang&ElixirFest ◦ Japan Elixir Association ◦ meguro.rb, meguro.es, etc • Hobby ◦ 仏像制作, 丸太収集, 写経, 寺社仏閣 ◦ 人工衛星/アマチュア無線 ◦ 自転車/ダイエット/脂肪燃焼
Target • AWSでサービスを運用したい人 • EC2ではなくコンテナでサービスを運用したい人 • 簡単にサービスをセットアップしたい人 • Kubernetesの学習に挫折した人 •
モチベーション ◦ 運用サービス/システムが多すぎで管理がしんどい ◦ アプリはコンテナで運用したい ◦ ECS/EKSは便利だけどセットアップ・メンテする為に必要な知識が多すぎる ◦ ぱっとセットアップできて、いい感じにマネージしてくれるマネージドサービスが出たぞ
Goal • AppRunnerについて以下を理解する 1. AppRunnerの構成/アーキテクチャ 2. AppRunnerでできること・できないこと 3. AppRunnerで運用する際に気をつけること
AppRunnerとは • AWSのコンピューティング系の新サービス ◦ ソースコードのリポジトリ or コンテナイメージから Webアプリを簡単にデプロイ ◦ ネットワーク・ロードバランサー・
TLS証明書等の関連リソースを一括でセットアップ ◦ 同時リクエスト数に応じてオートスケールされる ◦ 簡単に一時停止&再開可能 ◦ サービスの実行分のみコスト請求される • 今(2021/6)のところソースコードからデプロイする場合のランタイムはPython3、 nodejs12のみ対応 ◦ これ以外のランタイムを利用したい場合は Dockerのコンテナレジストリからデプロイする必要があ る • 実際に動かして確認したい人はWORKSHOPがおすすめ ◦ https://www.apprunnerworkshop.com/
AppRunnerのアーキテクチャ user AppRunner ECR or initial & monitor code /
image AppRunner Service deploy web console API AWS CLI AWS SDK operation AppRunnerサービスのVPC LoadBalancer TLS証明書 AutoScaling container container container ・・・ Custom Domain CloudWatch logs github connection
Set Up AppRunner • GitHubのソースコードからdeployする場合 ◦ WORKSHOP参照(今回のプレゼンでは割愛します ) • コンテナイメージからdeployする場合
◦ アプリを作成 ◦ ECRにリポジトリを作成 ◦ AppRunnerサービスの作成 ◦ Dockerイメージの作成 ◦ ECRのリポジトリにイメージを push ◦ (必要に応じて)カスタムドメインの登録
Demo • AWSの事前準備 ◦ ECRリポジトリ ◦ RDS(Aurora/MySQL) ※ publicアクセス可能にしておく ◦
IAMロール • ソースコード ◦ aws: https://github.com/ohr486/blog-sample-aws-app-runner/tree/master/aws ◦ app: https://github.com/ohr486/blog-sample-aws-app-runner/tree/master/app • アプリ仕様 ◦ https://github.com/ohr486/blog-sample-aws-app-runner/blob/master/app/app/controllers/info_c ontroller.rb ◦ /info/cpu => アプリが動作するサーバー /コンテナのCPU情報を出力 ▪ cat /proc/cpuinfo ◦ /info/mem => アプリが動作するサーバー /コンテナのメモリ情報を出力 ▪ cat /proc/meminfo
App概要(1) container expose 8080 (HTTP) rails puma MySQL driver entrypoint.sh
= DB Migration = = Railsの起動 = expose 3306 (MySQL)
App概要(1) • Dockerfile ◦ https://github.com/ohr486/blog-sample-aws-app-runner/blob/master/app/Dockerfile.apprunne1 • entrypoint.sh ◦ https://github.com/ohr486/blog-sample-aws-app-runner/blob/master/app/ep.apprunner1.sh •
puma.rb ◦ https://github.com/ohr486/blog-sample-aws-app-runner/blob/master/app/config/puma1.rb
AppRunnerでできること • 負荷分散(ロードバランシング) • HTTPS通信(証明書発行) • オートスケーリング • 自動Deploy
AppRunnerでできないこと • バッチ・タスクスケジューラー ◦ RailsでいうところのSidekiqの様な非同期処理 • FireWall (WAF) • WebSocket通信
• コンテナへ内のプロセスへのAttach/Exec(REPL) • Webサーバー ◦ nginx/apacheの様な大量のコネクションの処理機構 • ログ転送(サイドカー) • apprunner-roadmap ◦ https://github.com/aws/apprunner-roadmap/issues
App概要(2) webサーバーを追加 container expose 8080 (HTTP) /app/tmp/sockets/puma.sock nginx listen 8080;
upstream sock rails puma bind unix domain sock MySQL driver entrypoint.sh = DB Migration = = Railsの起動 = = nginxの起動 = expose 3306 (MySQL) proxy
App概要(3) ログコレクタを追加 container expose 8080 (HTTP) /app/tmp/sockets/puma.sock nginx listen 8080;
upstream sock rails puma bind unix domain sock MySQL driver entrypoint.sh = fluentdの起動 = = DB Migration = = Railsの起動 = = nginxの起動 = expose 3306 (MySQL) logs fluentd expose 24224 (fluentd)
AppRunnerに足りないもの • WebAppの運用上困るもの/こと ◦ 選択できるCPU/Memoryのバリエーション(1vCPU/2vCPU, 2GB/3GB/4GB)が少ない ◦ Dockerイメージ(Dockerfile)が複雑になる(ベストプラクティスから逸脱する ) ▪
https://cloud.google.com/architecture/best-practices-for-building-containers?hl=ja ◦ Dockerで複数のプロセスを起動するので何かしらのプロセス管理の機構が必要 ▪ https://matsuand.github.io/docs.docker.jp.onthefly/config/containers/multi-service_contai ner/ ◦ Blue/Green Deploy・カナリアリリースの仕組み ▪ AWSの既存サービス(Route53 etc)を組み合わせてがんばればなんとかなるけど、煩雑にな る • セキュリティ上困るもの/こと ◦ AppRunnerからPrivateなSubnetへのアクセスができない
App概要(4) ネットワーク AWSのネットワーク AppRunnerサービスのVPC LoadBalancer AutoScaling container 運用アカウントのネットワーク 運用サービスのVPC publicなsubnet
privateなsubnet 通信できない 通信可能 RDS ElastiCache internet RDS ElastiCache Aurora Serverless 仕様上privateな subnetにDBを配 置できない DBはprivateな subnetに配置し たいができない
まとめ • AppRunnerの概要について紹介しました • ソース/Dockerイメージから簡単にWebAppに必要なリソース一式をdeployできる 事を開設しました • ただし今(2021/6)時点では本番運用に足りない機能・仕組みが散見します ◦ FireWall,
ログ転送, バッチ, WebSocket, etc ◦ Privateなネットワークへのアクセス ◦ マシンspec(vCPU/Mem)のバリエーション ◦ etc • AWSの改善に期待しましょう