Amplify Storage のセットアップ
前提条件
以下の手順が完了していることを確認してください:
バックエンドストレージをプロビジョニングする
AWS Amplify Storage モジュールは、アプリのユーザーコンテンツを公開、保護、またはプライベートストレージバケットで管理するためのシンプルなメカニズムを提供します。Storage カテゴリには Amazon S3 の組み込みサポートが付属しています。
バックエンドでストレージリソースのプロビジョニングを開始するには、プロジェクトディレクトリに移動して 以下のコマンドを実行 してください:
amplify add storageプロンプトで以下のように入力してください:
? Please select from one of the below mentioned services: `Content (Images, audio, video, etc.)`? You need to add auth (Amazon Cognito) to your project in order to add storage for user files. Do you want to add auth now? `Yes`? Do you want to use the default authentication and security configuration? `Default configuration`? How do you want users to be able to sign in? `Username`? Do you want to configure advanced settings? `No, I am done.`? Please provide a friendly name for your resource that will be used to label this category in the project: `S3friendlyName`? Please provide bucket name: `storagebucketname`? Who should have access: `Auth and guest users`? What kind of access do you want for Authenticated users? `create/update, read, delete`? What kind of access do you want for Guest users? `create/update, read, delete`? Do you want to add a Lambda Trigger for your S3 Bucket? `No`変更をクラウドにプッシュするには、以下のコマンドを実行 してください:
amplify pushバックエンドが正常に更新されると、新しい設定ファイル amplifyconfiguration.json がソースディレクトリ (例: '/src') にコピーされます。
アプリケーションを設定する
yarn または npm で Amplify をアプリに追加します:
npm install aws-amplifyImport and load the configuration file in your app. It's recommended you add the Amplify configuration step to your app's root entry point. For example index.js in React or main.ts in Angular.
import { Amplify } from 'aws-amplify';import amplifyconfig from './amplifyconfiguration.json';
Amplify.configure(amplifyconfig);Amplify CLI を使用したモックとローカルテスト
Amplify CLI は Amazon S3 でアプリケーションをテストするためのローカルモックサーバーの実行をサポートしています。詳細については CLI ツールチェーンドキュメントを参照してください。