Page updated Nov 22, 2023

Manual installation

The easiest way to get started with AWS Amplify is through npm with create-amplify, which is the workflow our quickstart recommends. However, for some use cases, it may be preferable to start from scratch, either with a brand new directory or an existing frontend app. This guide will walk you through how to initialize your project, install dependencies, and author your first backend.

Manual setup

First, if your frontend framework of choice doesn't have it already, create your project's package.json with npm init -y. Then, install the Amplify dependencies for building a backend:

npm add --save-dev @aws-amplify/backend @aws-amplify/backend-cli typescript
1npm add --save-dev @aws-amplify/backend @aws-amplify/backend-cli typescript

Note: TypeScript is not a requirement but is recommended for an optimal experience.

Next, create the entry point for your backend, amplify/backend.ts, with the following code:

import { defineBackend } from '@aws-amplify/backend'; defineBackend({});
1import { defineBackend } from '@aws-amplify/backend';
2
3defineBackend({});

Now you can run npx amplify sandbox to create your first backend!

Amplify (Gen 2) requires your backend to be configured for use with ECMAScript modules (ESM). If you encounter the following error during amplify sandbox, consider modifying your package.json with "type": "module":

The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@aws-amplify/backend")' call instead.
1The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@aws-amplify/backend")' call instead.

Or, you can create a local file in the Amplify backend directory, amplify/package.json:

{ "type": "module" }
1{
2 "type": "module"
3}

You can use define* functions to define your resources. For example, you can define authentication:

import { defineAuth } from '@aws-amplify/backend'; export const auth = defineAuth({ loginWith: { email: true } });
1import { defineAuth } from '@aws-amplify/backend';
2
3export const auth = defineAuth({
4 loginWith: {
5 email: true
6 }
7});

Or define your data resource:

import { a, defineData, type ClientSchema } from '@aws-amplify/backend'; const schema = a.schema({}); export type Schema = ClientSchema<typeof schema>; export const data = defineData({ schema });
1import { a, defineData, type ClientSchema } from '@aws-amplify/backend';
2
3const schema = a.schema({});
4
5export type Schema = ClientSchema<typeof schema>;
6export const data = defineData({
7 schema
8});

Each of these newly defined resources are then imported and set in the backend definition:

import { defineBackend } from '@aws-amplify/backend'; import { auth } from './auth/resource.js'; import { data } from './data/resource.js'; defineBackend({ auth, data });
1import { defineBackend } from '@aws-amplify/backend';
2import { auth } from './auth/resource.js';
3import { data } from './data/resource.js';
4
5defineBackend({
6 auth,
7 data
8});

Upgrade existing projects

You can also update an existing frontend app. To upgrade existing Amplify code-first DX (Gen 2) apps, use your Node.js package manager (for example, npm) to update relevant backend packages:

npm update @aws-amplify/backend @aws-amplify/backend-cli
1npm update @aws-amplify/backend @aws-amplify/backend-cli

Next steps

We recommend the following next steps: