$30 off During Our Annual Pro Sale. View Details »

スタートアップでよく作るこの機能、サーバーレスならこうやります / Serverless Start up

kensh
November 17, 2022

スタートアップでよく作るこの機能、サーバーレスならこうやります / Serverless Start up

スタートアップでは少ない人数で最大限の価値を生み出す工夫をどの企業でも考えていらっしゃると思います。
アイデアが浮かんだらそれが成功するか失敗するかは、頭の中で考えていても分かりません。
まずは作って市場で試してみることから始めるということをスタートアップの皆様は実行されているはずです。
そのアイデアを実現するために AWS のサーバーレスがどのようにお役に立てるかお話ししたいと思います。

kensh

November 17, 2022
Tweet

More Decks by kensh

Other Decks in Technology

Transcript

  1. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Kensuke Shimokawa / _kensh
    Snr. Serverless Specialist
    Amazon Web Services Japan G.K.
    スタートアップでよく作る
    この機能、サーバーレスなら
    こうやります
    AWS Startup Tech Meetup 福岡
    Slides https://speakerdeck.com/_kensh/
    Qiita https://qiita.com/_kensh

    View Slide

  2. Kensuke Shimokawa / _kensh
    Snr. Serverless Specialist
    Amazon Web Service Japan
    ---
    work:
    - サーバーレス技術
    - 地域創⽣
    Slides https://speakerdeck.com/_kensh/
    Qiita https://qiita.com/_kensh
    趣味︓図書館のヘビーユーザー

    View Slide

  3. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    © 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    ローカル x スタートアップ が
    サーバーレスを使うべき理由

    View Slide

  4. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    ローカル x スタートアップ がサーバーレスを使うべき理由
    サーバーを管理している時間も労力もかけたくない
    ビジネスに集中したい
    実験的な環境を手に入れたい

    View Slide

  5. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    サーバーレスどうやって始めていくの?
    https://aws.amazon.com/jp/events/aws-event-resource/hands-on/

    View Slide

  6. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    © 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    スタートアップでよく作る
    この機能、サーバーレスなら
    こうやります

    View Slide

  7. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    UX を改善したい場合

    View Slide

  8. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    API まわりで UX を悪くするケース
    Endpoint Endpoint
    時間のか
    かる処理
    アクセスが集中する バックエンド処理に時間がかかる

    View Slide

  9. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    アクセスが集中する
    Endpoint
    処理
    202 Accepted
    キュー
    リクエストは⼀旦 202 Accepted でレスポンスされ、キューに⼊った
    メッセージは⾮同期に処理される

    View Slide

  10. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    バックエンド処理に時間がかかる
    Endpoint
    時間のか
    かる処理
    キュー
    202 Accepted
    時間のかかる処理は、⼀旦キューイングされてキューからメッセージ
    を取得する別のサービスによって処理される

    View Slide

  11. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    結果をどのように受け取るか
    • ユーザーアクション
    • 画⾯遷移時に取得
    • ボタンクリックなどのアクション
    • ポーリング
    • WebSocket

    View Slide

  12. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    バックエンド処理に時間がかかる
    Endpoint
    時間のか
    かる処理
    キュー
    WebSocket
    処理が終われば、処理プロセスがWebSocketを介してクライアントに
    結果通知を push する

    View Slide

  13. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    バックエンド処理に時間がかかる
    Endpoint
    時間のか
    かる処理
    キュー
    WebSocket
    Amazon API Gateway

    View Slide

  14. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    バックエンド処理に時間がかかる
    Endpoint
    時間のか
    かる処理
    キュー
    WebSocket
    Amazon API Gateway Amazon SQS

    View Slide

  15. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    バックエンド処理に時間がかかる
    Endpoint
    時間のか
    かる処理
    キュー
    WebSocket
    Amazon API Gateway AWS Lambda
    Amazon SQS
    AWS のサーバーレスサービスに当てはめると、Endpoint実装には API Gateway
    キューイングには SQS、そして処理には Lambdaが使える

    View Slide

  16. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    同期 API との共存
    Endpoint
    時間のか
    かる処理
    キュー
    WebSocket
    Amazon API Gateway AWS Lambda
    Endpoint
    処理
    非同期
    同期
    Amazon SQS
    同期処理と⾮同期処理は、どちらかだけ利⽤するという感じではなく
    両⽅をアーキテクチャに組み込むことができる

    View Slide

  17. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    サクッとWebhookしたい場合

    View Slide

  18. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Webhook を投げる側
    AWS Step Functions
    Express Workflow
    Amazon API Gateway
    HTTP
    Endpoint
    Lambda
    function Amazon SNS
    Amazon EventBridge
    Lambda
    function
    HTTP
    Endpoint
    ⾮同期
    ⾮同期
    ⾮同期
    Subscription
    API Destination
    HTTP Integration
    import requests
    url = 'https://example.com/'
    response = requests.get(url)
    同期
    retry rate
    retry
    rate
    auth
    auth
    DLQ
    retry
    DLQ
    外部 API 呼び出しを⾮同期的に扱えないか
    waiting…
    Round-trip
    latency

    View Slide

  19. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Amazon EventBridge
    異なるチーム間の Push型での情報連携(イベント通知)を可能にするイベントバス
    AWS Cloud
    AWS Cloud
    AWS Cloud
    Amazon
    EventBridge

    View Slide

  20. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Webhook を投げる側
    function Amazon EventBridge
    ⾮同期
    API Destination
    SaaS や 別システムで公開して
    いる Webhook にメッセージを
    送信する際に
    EventBridge API Destination
    が利⽤できる

    View Slide

  21. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Webhook を受ける側
    functionURL
    SaaS や 別システムに設定する
    Webhook ⽤のAPI endpointが
    必要な場合
    AWS Lambda functionURL
    が利⽤できる

    View Slide

  22. Web アプリケーションを
    AWS 上でサクッと動かしたい場合

    View Slide

  23. AWS サービスを組み合わせてインフラを構築
    柔軟性が⾼い
    VPC (ネットワーク)
    Fargate (コンピュート)
    ECS (オーケストレーション)
    ALB (ロードバランサ)
    AWS Auto Scaling (オートスケール)
    CodeBuild (CI/CD)
    ⼿間がかかる

    View Slide

  24. 構築済みのインフラにすぐにデプロイ
    AWS App Runner

    View Slide

  25. App Runner とは
    インフラや AWS についての経験がなくても、
    コンテナ化されたウェブアプリケーションや API を
    簡単かつ迅速に AWS 上で動かせるサービス

    View Slide

  26. App Runner 上にウェブアプリケーションをデプロイ
    App Runner
    GitHub
    動かしたいウェブアプリケーションを指定する
    GitHub Repo

    View Slide

  27. App Runner 上にウェブアプリケーションをデプロイ
    App Runner
    GitHub
    ソースコードを取得
    コンテナイメージをビルドしてデプロイ
    コンテナインスタンス
    ロードバランサー
    ネットワーク (VPC)
    App Runner
    GitHub Repo

    View Slide

  28. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.

    View Slide

  29. App Runner 上にウェブアプリケーションをデプロイ
    コンテナインスタンス
    ロードバランサー
    ネットワーク (VPC)
    App Runner
    エンドユーザー デフォルトドメイン
    https://xxxxxxxx..awsapprunner.com

    View Slide

  30. もっと AWS App Runner を知りたい⽅へ
    公式ドキュメント
    https://docs.aws.amazon.com/apprunner/latest/dg/what-is-apprunner.html
    ブログ
    https://aws.amazon.com/jp/blogs/news/introducing-aws-app-runner/
    ワークショップ
    https://www.apprunnerworkshop.com/
    ロードマップ
    https://github.com/aws/apprunner-roadmap/projects/1

    View Slide

  31. • 福岡のスタートアップが”できていること”を全国に展開したい
    福岡が例外的に特殊、から、他の地域でも当たり前に
    • AWS からの発信よりもスタートアップやコミュニティの発信
    の⽅が価値が⾼い
    “会場にこの後もいるので、話をさせてください。”
    • アイデアを素早く答え合わせする
    そのためにサーバーレスの実験的環境は便利
    さいごに – お伝えしたかったこと -

    View Slide

  32. Thank you
    © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Kensuke Shimokawa
    _kensh
    Slides https://speakerdeck.com/_kensh/
    Qiita https://qiita.com/_kensh

    View Slide

  33. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    © 2021, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Appendix

    View Slide

  34. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    #AWSBuilders
    FunctionURL blog
    https://itnext.io/using-aws-lambda-function-url-to-build-a-serverless-backend-for-slack-a292ef355a5d

    View Slide

  35. AWS は幅広い選択肢を提供

    View Slide

  36. AWS は幅広い選択肢を提供
    200 以上のサービス

    View Slide

  37. AWS App Runner の主な特徴
    シンプルな
    オートスケーリング
    統合された
    メトリクス・ロギング機能
    シンプルな
    セットアップ

    View Slide

  38. AWS App Runner の主な特徴
    シンプルな
    オートスケーリング
    統合された
    メトリクス・ロギング機能
    シンプルな
    セットアップ

    View Slide

  39. App Runner 上にウェブアプリケーションをデプロイ
    App Runner
    Amazon ECR
    Image Repo
    動かしたいウェブアプリケーションを指定する

    View Slide

  40. App Runner 上にウェブアプリケーションをデプロイ
    App Runner
    コンテナインスタンス
    ロードバランサー
    ネットワーク (VPC)
    App Runner
    コンテナイメージを取得
    コンテナイメージをデプロイ
    Amazon ECR
    Image Repo

    View Slide

  41. AWS App Runner の主な特徴
    シンプルな
    オートスケーリング
    統合された
    メトリクス・ロギング機能
    シンプルな
    セットアップ

    View Slide

  42. App Runner - シンプルなオートスケーリングの設定
    オートスケールのしきい値
    となるリクエスト数
    コンテナインスタンスの
    最⼩数
    コンテナインスタンスの
    最⼤数
    デフォルト
    の設定値

    View Slide

  43. オートスケール
    コンテナインスタンス
    ロードバランサー
    ネットワーク (VPC)
    App Runner
    エンドユーザー デフォルトドメイン
    エンドユーザー
    エンドユーザー

    View Slide

  44. オートスケール
    コンテナインスタンス
    ロードバランサー
    ネットワーク (VPC)
    App Runner
    エンドユーザー デフォルトドメイン
    エンドユーザー
    エンドユーザー

    View Slide

  45. AWS App Runner の主な特徴
    シンプルな
    オートスケーリング
    統合された
    メトリクス・ロギング機能
    シンプルな
    セットアップ

    View Slide

  46. ログ・メトリクス
    ロードバランサー
    App Runner 開発者
    App Runner コンソール
    コンテナインスタンス
    ログとメトリクスを⾃動で収集
    App Runner コンソールから確認

    View Slide

  47. App Runner - Console でのログの閲覧
    ⾃分でログエージェントを実装する必要なし

    View Slide

  48. App Runner - Console でのメトリクスの閲覧
    リクエスト数、応答のレイテンシ、HTTP 2XX 4XX 5XX それぞれの数
    を App Runnerのコンソール画⾯で閲覧可能

    View Slide