Page updated Apr 3, 2024

Preview: AWS Amplify's new code-first DX (Gen 2)

The next generation of Amplify's backend building experience with a TypeScript-first DX.

Get started

Set up fullstack project

To get started, initialize a new React Native project.

Amplify now requires native modules not available through the Expo SDK. As a result, Expo Go is no longer supported but you should still be able to use Expo. Learn more about dropping support for Expo Go in Amplify v6.

Create a new app with the following command:

1npx create-expo-app amplified_todo
2
3cd amplified_todo

Start the app with the following command:

For Android:

1npx expo run:android

For iOS:

1npx expo run:ios

Follow 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:

1npx react-native init amplified_todo
2
3cd amplified_todo

Start the app with the following command:

1npm start
1r - reload the app
2d - open developer menu
3i - run on iOS
4a - run on Android

Initialize 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:

1amplify init

When you initialize Amplify you'll be prompted for some information about the app:

1? Enter a name for the project (amplified_todo)
2The following configuration will be applied:
3
4Project information
5| Name: amplified_todo
6| Environment: dev
7| Default editor: Visual Studio Code
8| App type: javascript
9| Javascript framework: react-native
10| Source Directory Path: /
11| Distribution Directory Path: /
12| Build Command: npm run-script build
13| Start Command: npm run-script start
14
15? Initialize the project with the above configuration? Yes
16Using default provider awscloudformation
17? Select the authentication method you want to use: AWS profile
18? Please choose the profile you want to use default

When you initialize a new Amplify project, a few things happen:

  • It creates a top level directory called amplify that stores your backend definition. During the tutorial you'll add cloud capabilities, such as GraphQL API and web hosting. As you add these features, the amplify folder 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.json in 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 .gitignore file, adding some generated files to the ignore list

Install Amplify Libraries

Install the necessary dependencies by running the following command:

1npm install aws-amplify @aws-amplify/react-native @react-native-community/netinfo @react-native-async-storage/async-storage react-native-get-random-values
Instructions 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:

1- platform :ios, min_ios_version_supported
2 + platform :ios, 13.0
1npm install aws-amplify @aws-amplify/react-native @react-native-community/netinfo @react-native-async-storage/async-storage react-native-get-random-values

You will also need to install the pod dependencies for iOS:

1npx pod-install

After installing pod dependencies, rebuild the app:

1npm run ios

Note: Be sure to install @react-native-async-storage/async-storage and react-native-get-random-values or you will face errors at runtime.

1// App.js
2
3import { Amplify } from 'aws-amplify';
4import amplifyconfig from './src/amplifyconfiguration.json';
5Amplify.configure(amplifyconfig);
1// index.js
2
3import { Amplify } from 'aws-amplify';
4import amplifyconfig from './src/amplifyconfiguration.json';
5Amplify.configure(amplifyconfig);

Make sure you call Amplify.configure as early as possible in your application’s life-cycle. A missing configuration or NoCredentials error is thrown if Amplify.configure has not been called before other Amplify JavaScript APIs. Review the Library Not Configured Troubleshooting guide for possible causes of this issue.

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.