Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Oct 11, 2024

Set up fullstack project

For new Amplify apps, we recommend using Amplify Gen 2. You can learn more in our Gen 2 Docs.

This tutorial is built using the Next.js App Router.

To set up the project, you'll first create a new Next.js app with Create Next App, a simple CLI tool that enables you to quickly start building a new Next.js application, with everything set up for you. You'll then add Amplify and initialize a new project.

From your projects directory, run the following commands:

npm create next-app@14 -- next-amplified --ts --no-eslint --src-dir --import-alias '@/*' --no-tailwind --app
cd next-amplified

This command will bootstrap the project with the following options:

  • App Router
  • TypeScript
  • No ESLint
  • With the src directory
  • No Tailwind CSS
  • imports aliased to @/ (the default)

Now that you're in the root of the project, you can run the app by using the following command:

npm run dev

This runs a development server and allows us to see the output generated by the build, you can see the running app by navigating to \http://localhost:3000>.

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:

amplify init

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

? Enter a name for the project (nextamplified)
The following configuration will be applied:
Project information
| Name: next-amplified
| Environment: dev
| Default editor: Visual Studio Code
| App type: javascript
| Javascript framework: react
| Source Directory Path: src
| Distribution Directory Path: build
| Build Command: npm run-script build
| Start Command: npm run-script start
? Initialize the project with the above configuration? Yes
Using default provider awscloudformation
? Select the authentication method you want to use: AWS profile
For more information on AWS Profiles, see:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html
? 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

The aws-amplify package is the main library for working with Amplify Libraries in your projects. The @aws-amplify/adapter-nextjs package includes additional Next.js-specific functions for using the Amplify libraries server-side:

npm install aws-amplify @aws-amplify/adapter-nextjs

That's all it takes to install Amplify libraries with your Next.js application. Next, we'll create a new backend API and database tables. Then, we'll use the Amplify library's Next.js adapter to make API requests to your new backend.