Set up fullstack project
To get started, initialize a new React Native project for Android or iOS.
Create a new app with the following command:
npx create-expo-app amplified_todo
cd amplified_todoStart the app with the following command:
For Android:
npx expo run:androidFor iOS:
npx expo run:iosFollow the additional prompts to configure your build and allow it some time to process. When ready, you app should launch in the respective simulator.
After you setup development environment, create a new app with the following command:
npx react-native init amplified_todo
cd amplified_todoStart the app with the following command:
npm startr - reload the appd - open developer menui - run on iOSa - run on AndroidInitialize a new backend
Now that you have a running app, it's time to set up Amplify so that you can create the necessary backend services needed to support the app.
Open a new terminal. From the root of the project, run:
amplify initWhen you initialize Amplify you'll be prompted for some information about the app:
? Enter a name for the project (amplified_todo)The following configuration will be applied:
Project information| Name: amplified_todo| Environment: dev| Default editor: Visual Studio Code| App type: javascript| Javascript framework: react-native| Source Directory Path: /| Distribution Directory Path: /| Build Command: npm run-script build| Start Command: npm run-script start
? Initialize the project with the above configuration? YesUsing default provider awscloudformation? Select the authentication method you want to use: AWS profile? Please choose the profile you want to use defaultWhen you initialize a new Amplify project, a few things happen:
- It creates a top level directory called
amplifythat stores your backend definition. During the tutorial you'll add cloud capabilities, such as GraphQL API and web hosting. As you add these features, theamplifyfolder will grow with infrastructure-as-code templates that define your backend stack. Infrastructure-as-code is a best practice way to create a replicable backend stack. - It creates a file called
amplifyconfiguration.jsonin your designated Source Directory Path that holds all the configuration for the services you create with Amplify. This is how the Amplify JavaScript client library is able to get the necessary information to connect to your backend services. - It modifies the
.gitignorefile, adding some generated files to the ignore list
Install Amplify Libraries
Install the necessary dependencies by running the following command:
npm install aws-amplify @aws-amplify/react-native @react-native-community/netinfo @react-native-async-storage/async-storage react-native-get-random-valuesInstructions for React Native version 0.72 and below
@aws-amplify/react-native requires a minimum iOS deployment target of 13.0 if you are using react-native version less than or equal to 0.72. Open the Podfile located in the ios directory and update the target value:
- platform :ios, min_ios_version_supported + platform :ios, 13.0npm install aws-amplify @aws-amplify/react-native @react-native-community/netinfo @react-native-async-storage/async-storage react-native-get-random-valuesYou will also need to install the pod dependencies for iOS:
npx pod-installAfter installing pod dependencies, rebuild the app:
npm run ios// App.js
import { Amplify } from 'aws-amplify';import amplifyconfig from './src/amplifyconfiguration.json';Amplify.configure(amplifyconfig);// index.js
import { Amplify } from 'aws-amplify';import amplifyconfig from './src/amplifyconfiguration.json';Amplify.configure(amplifyconfig);And that's all it takes to configure Amplify. As you add or remove categories and make updates to your backend configuration using the Amplify CLI, the configuration in amplifyconfiguration.json will update automatically.
Now that your app is set up and Amplify is initialized, you can add an API in the next step.