Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Amplifyで Webアプリケーションの 堅固な土台をサクッと構築する方法

Amplifyで Webアプリケーションの 堅固な土台をサクッと構築する方法

プロダクション利用可能な Web アプリのホスティング環境として
Amplifyで 堅固な土台をサクッと構築する方法についてお伝えします。

kawasaki-teruo

July 29, 2022
Tweet

More Decks by kawasaki-teruo

Other Decks in Technology

Transcript

  1. 3
 アジェンダ
 • Amplify 概要
 • Amplify の魅力
 • 本セッションの位置付け


    • 堅固な土台の作り方 (3点セット)
 • React の OSS をホスティングしてみた

  2. 4
 AWS Hands-on for Beginners(初心者向けハンズオン)
 AWS Amplify を用いた Web サイトの構築方法を学ぼう


    https://pages.awscloud.com/JAPAN-event-OE-Hands-on-for-Beginners-amplify-2022-reg-event.html 
 https://aws.amazon.com/jp/blogs/news/aws-hands-on-for-beginners-19/ 

  3. 13
 • amplify add auth
 → ログイン
 • amplify add

    hosting
 → ホスティング
 • amplify env add
 → マルチ環境

  4. 19
 初心者向けハンズオンの構成
 環境構築 CLI編 手順
 • Node.js 環境のセットアップ(Cloud9 ではインストール済み)
 ◦

    $ node –v
 • Amplify CLI のインストールとセットアップ
 ◦ $ npm install -g @aws-amplify/cli
 ◦ $ amplify configure
 • Reactアプリの作成
 ◦ $ npx create-react-app hands-on-todo
 • Amplify Project の初期化コマンド
 ◦ $ amplify init
 • Amplify Framework のインストール
 ◦ $ npm install aws-amplify @aws-amplify/ui-react

  5. 20
 初心者向けハンズオンの構成
 FE/API/DB編 手順
 • Amplify CLI で API の追加


    ◦ $ amplify add api
 • AWS への反映
 ◦ $ amplify status
 ◦ $ amplify push
 • Amplify Docs 内にあるサンプルコードを追加
 ◦ リンク
 • 動作確認
 ◦ $ npm start

  6. 21
 初心者向けハンズオンの構成
 Auth編 手順
 • Amplify CLI で Auth の追加


    ◦ $ amplify add auth
 • AWS へ反映
 ◦ $ amplify status
 ◦ $ amplify push
 • Amplify Docs 内の記載内容の通りにコードを修正
 ◦ リンク
 • 動作確認
 ◦ $ npm start

  7. 22
 初心者向けハンズオンの構成
 Hosting編 手順
 • アプリケーションのホスティング
 ◦ $ amplify add

    hosting
 • クラウドリソースの変更とホスティングするアプリのビルド、デプロイ
 ◦ $ amplify publish
 • 動作確認

  8. 24
 「堅固な土台の作り方」の手順
 • 環境構築 Cloud9編
 • 環境構築 CLI編
 • FE/API/DB編


    • Hosting編
 ◦ Auth編と順序を入れ替え
 ◦ 手動デプロイ → 継続的デプロイ
 • Auth編
 ◦ デフォルト設定 → デフォルト設定+ソーシャルサインイン
 • Env編(追加)
 概要欄からブログをご確認ください

  9. 27
 Cloud9 のセットアップ
 • Cloud9 インスタンスの作成
 • Cloud9 の環境設定
 ◦

    クレデンシャルの設定
 • 「AWS Managed temporary credentials」をオフに
 ◦ EBS ボリュームの容量を拡張
 • ボリュームのサイズ 10GB → 32GB
 • Cloud9 のプレビューURL確認
 Amplify ハンズオンを実行するための Cloud9 の設定変更について

  10. 29
 「堅固な土台の作り方」の手順
 Amplify CLI 環境構築
 • 作成済みの IAM ユーザの認証情報を設定
 ◦

    $ aws configure
 • Amplify CLI のインストール
 ◦ $ npm install -g @aws-amplify/cli
 • Reactアプリの作成
 ◦ $ npx -y create-react-app app-base
 • Amplify Project の初期化コマンド
 ◦ $ amplify init -y
 • Amplify Framework のインストール
 ◦ $ npm install aws-amplify @aws-amplify/ui-react
 概要欄からブログをご確認ください

  11. 31
 「堅固な土台の作り方」の手順
 ホスティング
 • GitHub新規リポジトリ作成
 ◦ $ git init
 ◦

    $ git push -u origin main
 • amplify add hosting コマンド実行
 ◦ 継続的デプロイ設定開始
 • Amplify コンソール からデプロイ設定
 ◦ GitHubリポジトリを指定
 ◦ ビルド設定
 • 動作確認
 概要欄からブログをご確認ください

  12. amplify add hosting 実行
 ? Select the plugin module to

    execute … (Use arrow keys or type to filter) 
 ❯ Hosting with Amplify Console (Managed hosting with custom domains, Continuous deployment) Amazon CloudFront and S3 Hosting with Amplify Console 
 を選択
 ? Choose a type (Use arrow keys) 
 Continuous deployment (Git-based deployments) ❯ Manual deployment Learn more Continuous deployment 
 を選択
 ? Continuous deployment is configured in the Amplify Console. Please hit enter once you connect your repository 左記のメッセージが表示されたら 
 ブラウザでAWSマネジメントコンソールを表示 し、Amplify の画面を開きます 
 34
 ホスティング

  13. 43
 「堅固な土台の作り方」の手順
 ホスティング
 • GitHub新規リポジトリ作成
 ◦ $ git init
 ◦

    $ git push -u origin main
 • amplify add hosting コマンド実行
 ◦ 継続的デプロイ設定開始
 • Amplify コンソール からデプロイ設定
 ◦ GitHubリポジトリを指定
 ◦ ビルド設定
 • 動作確認

  14. 45
 「堅固な土台の作り方」の手順
 ログイン
 • ソーシャルサインイン設定確認
 ◦ Google Oauth の 「クライアント

    ID」「クライアント シークレット」を確認
 • ログイン設定追加
 ◦ $ amplify add auth
 ◦ Google Oauth 側にも反映
 • フロントエンドにログインを確認できるコード追加
 ◦ src/App.js を修正
 ◦ $ git push
 • 動作確認
 ◦ $ npm start
 概要欄からブログをご確認ください

  15. 46
 ログイン
 • ソーシャルサインイン設定確認
 ◦ 事前に GCP のサイトで Google Oauth

    を登録
 ◦ クライアント ID / クライアント シークレット をメモ
 • リダイレクトURLをメモ
 ◦ Cloud9 環境のプレビュー URL
 ◦ デプロイ先のホスティング URL

  16. 47
 ログイン
 amplify add auth を実行(1/3)
 Do you want to

    use the default authentication and security configuration? (Use arrow keys) ❯ Default configuration Default configuration with Social Provider (Federation) Manual configuration I want to learn more. Default configuration with Social Provider を選択 How do you want users to be able to sign in? ❯ Username Email Phone Number Email or Phone Number I want to learn more. Username を選択 Do you want to configure advanced settings? No, I am done. Yes, I want to make some additional changes. No を選択 What domain name prefix do you want to use? (appnamexxxxxxxx-xxxxxxxx) デフォルト値を利用 次のスライドに続きます

  17. 48
 ログイン
 amplify add auth を実行(2/3)
 Enter your redirect signin

    URI: プレビューURL を入力 Do you want to add another redirect signin URI (y/N) → Yes Y を選択 Enter your redirect signin URI: ホスティングURL を入力 Do you want to add another redirect signin URI (y/N) → No N を選択 Enter your redirect signout URI: プレビューURL を入力 Do you want to add another redirect signout URI (y/N)→ Yes Y を選択 Enter your redirect signout URI: ホスティングURL を入力 Do you want to add another redirect signout URI (y/N)→ No N を選択 次のスライドに続きます 

  18. amplify add auth を実行(3/3)
 49
 ログイン
 • デプロイ先へ反映
 ◦ $

    amplify push -y
 • Google Oauth 側にも設定内容を反映します
 Select the social providers you want to configure for your user pool: (Press <space> to select, <a> to toggle all, <i> to invert selection) ◯ Facebook ◉ Google ◯ Login With Amazon ◯ Sign in with Apple カーソルキーで上下に移動 スペースキーを押して選択 enterキーを押して次へ You've opted to allow users to authenticate via Google. If you haven't already, you'll need to go to https://developers.google.com/identity and create an App ID. Enter your Google Web Client ID for your OAuth flow: クライアント ID を入力 Enter your Google Web Client Secret for your OAuth flow: クライアント シークレット を入力
  19. 52
 「堅固な土台の作り方」の手順
 ログイン
 • ソーシャルサインイン設定確認
 ◦ Google Oauth の 「クライアント

    ID」「クライアント シークレット」を確認
 • ログイン設定追加
 ◦ $ amplify add auth
 ◦ Google Oauth 側にも反映
 • フロントエンドにログインを確認できるコード追加
 ◦ src/App.js を修正
 ◦ $ git push
 • 動作確認
 ◦ $ npm start
 概要欄からブログをご確認ください

  20. 54
 「堅固な土台の作り方」の手順
 マルチ環境
 • 新規環境として production を追加 
 ◦ $

    amplify env add
 • develop ブランチ追加
 ◦ $ git checkout -b develop
 • ブランチと環境の紐付けを修正
 ◦ main ブランチ → production 環境
 ◦ develop ブランチ → dev 環境
 • dev環境のログイン設定変更
 ◦ $ amplify update auth
 
 概要欄からブログをご確認ください

  21. 55
 マルチ環境
 amplify env add を実行
 ? Enter a name

    for the environment 「production」と入力 Using default provider awscloudformation ? Select the authentication method you want to use: (Use arrow keys) ❯ AWS profile AWS access keys ? Please choose the profile you want to use (Use arrow keys) ❯ default Enter your Google Web Client ID for your OAuth flow: クライアント ID を入力 Enter your Google Web Client Secret for your OAuth flow: クライアント シークレット を入力 • デプロイ先へ反映
 ◦ $ amplify push -y

  22. 59
 マルチ環境
 dev環境のログイン設定変更
 $ amplify update auth(1/3)
 Please note that

    certain attributes may not be overwritten if you choose to use defaults settings. Using service: Cognito, provided by: awscloudformation What do you want to do? (Use arrow keys) ❯ Apply default configuration without Social Provider (Federation) Walkthrough all the auth configurations Add/Edit signin and signout redirect URIs Update OAuth social providers Create or update Cognito user pool groups Create or update Admin queries API Add/Edit signin and signout redirect URIs を選択 次のスライドに続きます 

  23. dev環境のログイン設定変更
 $ amplify update auth(2/3)
 60
 マルチ環境
 Which redirect signin

    URIs do you want to edit? (Press <space> to select, <a> to toggle all, <i> to invert selection) ❯◯ https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.vfs.cloud9.ap-northeast-1.amazonaws.com/ ◯ https://main.xxxxxxxxxxxxxx.amplifyapp.com/ enterキーを押して次へ Do you want to add redirect signin URIs? (Y/n) Y を入力 Enter your new redirect signin URI: dev環境のホスティングURL を入力 ? Do you want to add another redirect signin URI (y/N) N を入力 次のスライドに続きます 

  24. dev環境のログイン設定変更
 $ amplify update auth(3/3)
 61
 マルチ環境
 • デプロイ先へ反映
 ◦

    $ amplify push -y
 Which redirect signout URIs do you want to edit? (Press <space> to select, <a> to toggle all, <i> to invert selection) ❯◯ https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.vfs.cloud9.ap-northeast-1.amazonaws.com/ ◯ https://main.xxxxxxxxxxxxxx.amplifyapp.com/ enterキーを押して次へ Do you want to add redirect signout URIs? (Y/n) Y を入力 Enter your new redirect signout URI: dev環境のホスティングURL を入力 ? Do you want to add another redirect signout URI (y/N) N を入力
  25. 62
 「堅固な土台の作り方」の手順
 マルチ環境
 • 新規環境として production を追加 
 ◦ $

    amplify env add
 • develop ブランチ追加
 ◦ $ git checkout -b develop
 • ブランチと環境の紐付けを修正
 ◦ main ブランチ → production 環境
 ◦ develop ブランチ → dev 環境
 • dev環境のログイン設定変更
 ◦ $ amplify update auth
 
 概要欄からブログをご確認ください

  26. 90
 アジェンダ(再掲)
 • Amplify 概要
 • Amplify の魅力
 • 本セッションの位置付け


    • 堅固な土台の作り方 (3点セット)
 • React の OSS をホスティングしてみた

  27. 91
 まとめ
 • Amplify は どのアプリでも疎かにできない機能
 (=堅固な土台)がサクッと追加できる
 • 堅固な土台の作り方 の手順をまとめた


    • 初心者向けハンズオンからの NextStep
 • Amplify OSS ホスティング チャレンジ
 • Amplify コミュニティで情報共有していきましょう