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:
1amplify add storage
Enter the following when prompted:
1? Please select from one of the below mentioned services:2 `Content (Images, audio, video, etc.)`3? 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?4 `Yes`5? Do you want to use the default authentication and security configuration?6 `Default configuration`7? How do you want users to be able to sign in?8 `Username`9? Do you want to configure advanced settings?10 `No, I am done.`11? Please provide a friendly name for your resource that will be used to label this category in the project:12 `S3friendlyName`13? Please provide bucket name:14 `storagebucketname`15? Who should have access:16 `Auth and guest users`17? What kind of access do you want for Authenticated users?18 `create/update, read, delete`19? What kind of access do you want for Guest users?20 `create/update, read, delete`21? Do you want to add a Lambda Trigger for your S3 Bucket?22 `No`
To push your changes to the cloud, execute the command:
1amplify push
When 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
:
1npm install aws-amplify
1import { Amplify } from 'aws-amplify';2import amplifyconfig from './amplifyconfiguration.json';3
4Amplify.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.