Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.
Maintenance ModeYou are viewing Amplify Gen 1 documentation. Amplify Gen 1 has entered maintenance mode and will reach end of life on May 1, 2027. New project should use Amplify Gen 2. For existing Gen 1 projects, a migration guide and tooling are available to help you upgrade. Switch to the latest Gen 2 docs →

GraphQL変換とStorage

GraphQL Transform、Amplify CLI、およびAmplifyライブラリにより、アプリケーションにAmazon S3を使用した複雑なオブジェクトサポートを簡単に追加できます。

このドキュメントはAWS AppSync SDK for JavaScript(V2)を参照しており、現在メンテナンスモードになっています。アップグレードガイドファイルの操作ガイドで最新のガイダンスを参照してください。

注:DataStore対応のGraphQL APIでは複雑なオブジェクトはサポートされていません。

基本

S3オブジェクトサポートを追加するための最小限のステップは次のとおりです:

amplify add storageを使用してファイルを保持するAmazon S3バケットを作成します。

amplify add authを使用してAmazon Cognito User Poolsにユーザープールを作成します。

amplify add apiを使用してGraphQL APIを作成し、次の型定義を追加します:

type S3Object {
bucket: String!
region: String!
key: String!
}

S3Objectタイプを何らかの@modelタイプから参照します:

type Picture @model @auth(rules: [{ allow: owner }]) {
id: ID!
name: String
owner: String
# S3Objectタイプをフィールドから参照します。
file: S3Object
}

GraphQL Transformは関連する入力タイプの作成を処理し、Amazon DynamoDBのS3オブジェクトへのポインタを保存します。AppSync SDKおよびAmplifyライブラリは、ファイルのS3への透過的なアップロードを処理します。

クライアントアプリからS3オブジェクトを使用してミューテーションを実行します:

mutation ($input: CreatePictureInput!) {
createPicture(input: $input) {
id
name
visibility
owner
createdAt
file {
region
bucket
key
}
}
}