Set up Amplify Storage
Prerequisites
Make sure you have completed the below steps:
Provision backend storage
AWS Amplify Storage module provides a simple mechanism for managing user content for your app in public, protected or private storage buckets. The Storage category comes with built-in support for Amazon S3.
To start provisioning storage resources in the backend, go to your project directory and execute the command:
amplify add storageEnter the following when prompted:
? 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`To push your changes to the cloud, execute the command:
amplify pushWhen your backend is successfully updated, your new configuration file amplifyconfiguration.json is copied under your source directory, e.g. '/src'.
Configure your application
Add Amplify to your app with yarn or npm:
npm install aws-amplifyimport { Amplify } from 'aws-amplify';import amplifyconfig from './amplifyconfiguration.json';
Amplify.configure(amplifyconfig);Mocking and Local Testing with Amplify CLI
Amplify CLI supports running a local mock server for testing your application with Amazon S3. Please see the CLI toolchain documentation for more details.