Skip to main content
Build an iOS Application

Module 2: Initialize Amplify

In this module, you will install and configure the Amplify CLI

Introduction

Overview

Now that you have created an iOS application, you will want to continue development and add new features.

To start to use AWS Amplify in your application, you must install the Amplify command line, initialize the Amplify project directory, configure your project to use the Amplify libraries, and initialize Amplify libraries at runtime.

What you will accomplish

In this tutorial, you will:

  • Initialize a new Amplify project

  • Add Amplify libraries in your project

  • Initialize Amplify libraries at runtime

Key concepts

Amplify CLI – Using the Amplify CLI you can create, manage, and remove AWS services directly from your terminal.

Amplify libraries – Using Amplify libraries you can interact with AWS services from a web or mobile application.

Implementation

Time to complete

10 minutes

Services used

Install Amplify CLI

1. Install the CLI

To install AWS Amplify CLI, open Terminal, and enter the following command:

curl -sL https://aws-amplify.github.io/amplify-cli/install | bash && $SHELL

2. Configure the CLI

Configure it to connect to your AWS account by running the following command:

amplify configure

Follow the steps as instructed. You can find a more detailed guide here .

Initialize an Amplify backend

Initialize an Amplify backend

To create the basic structure of our backend, we first need to initialize the Amplify project directory and create our Cloud backend.

1. Initialize the backend

Open the Terminal , navigate to the root directory of your project and run the following command:

amplify init

2. Enter a name

You will be asked to enter a name for the project. Keep the default name , and then validate that the information is correct. The following code is an example.

? Enter a name for the project (GettingStarted)The following configuration will be applied: Project information| Name: GettingStarted| Environment: dev| Default editor: Visual Studio Code| App type: ios

3. Follow the prompts

Proceed with the remaining steps:

Initialize the project with the above configuration? (Y/n)      Y Select the authentication method you want to use: (Use arrow keys)      AWS profile Please choose the profile you want to use      default

4. Verify initialization

This will provision the resources in the backend and might take a few minutes. Once it's done, you will see the following information:

Deployment state saved successfully.✔ Initialized provider successfully.✅ Initialized your environment successfully.✅ Your project has been successfully initialized and connected 

Add Amplify libraries to your project

1. Add dependencies

Switch back to Xcode. Select File and choose Add Package Dependencies...

Screenshot showing the File menu in an iOS development environment with the 'Add Package Dependencies...' option highlighted, part of the Amplify getting started tutorial for building iOS apps.

2. Search for the Amplify library

Enter the Amplify Libraries for Swift GitHub repo URL (https://github.com/aws-amplify/amplify-swift ) into the search bar, and press Enter.

Make sure that  Up to Next Major Version  is selected from the  Dependency Rule  dropdown, and select Add Package.

Screenshot of the AWS Amplify Library for Swift documentation and setup within a 'Getting Started' tutorial for building an iOS app, showing amplify-swift package details and introductory information.

3. Select the library

Once the libraries are fetched, you will be asked to select which ones you wish to add to your target.

In the drop down, next to Amplify, choose GettingStarted.

Select None  in for the rest of the Package Products in the Add to Target section, and choose Add Package.

Screenshot of the 'Choose Package Products for amplify-swift' dialog in Xcode, showing a list of AWS Amplify and CoreML plugin packages to add to an iOS project as part of the AWS Amplify tutorial for building iOS apps.

Initialize Amplify at runtime

1. Modify the file

Open the GettingStartedApp.swift  file and replace its content with the following information:

import Amplifyimport SwiftUI@mainstruct GettingStartedApp: App {    init() {        do {            try Amplify.configure()            print("Initialized Amplify");        } catch {            print("Could not initialize Amplify: \(error)")        }    }    var body: some Scene {        WindowGroup {            NotesView()        }    }}

Verify your setup

1. Build the project

To verify everything works as expected, build the project.

Select the Product menu and then select Build , or press Cmd + B .

There should be no error.

Conclusion

You have initialized the Amplify project and are now ready to start adding features! In the next module, we will add an entire user authentication flow with just a few lines of code.

Add user authentication