Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

GraphQL transform and Storage

The GraphQL Transform, Amplify CLI, and Amplify Library make it simple to add complex object support with Amazon S3 to an application.

This documentation references the AWS AppSync SDK for JavaScript (V2), which is now in Maintenance mode. Please refer to the Upgrade Guide and the Working with Files guide for updated guidance.

Note: Complex objects are not supported by DataStore-enabled GraphQL APIs.

Basics

At a minimum the steps to add S3 Object support are as follows:

Create a Amazon S3 bucket to hold files via amplify add storage.

Create a user pool in Amazon Cognito User Pools via amplify add auth.

Create a GraphQL API via amplify add api and add the following type definition:

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

Reference the S3Object type from some @model type:

type Picture @model @auth(rules: [{ allow: owner }]) {
id: ID!
name: String
owner: String
# Reference the S3Object type from a field.
file: S3Object
}

The GraphQL Transform handles creating the relevant input types and will store pointers to S3 objects in Amazon DynamoDB. The AppSync SDKs and Amplify library handle uploading the files to S3 transparently.

Run a mutation with S3 objects from your client app:

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