Task 2: Initialize the Amplify Backend
In this task, you will use AWS Amplify to provision a cloud backend for the app.
Introduction
Implementation
Set up Amplify Auth
The app uses email as the default login mechanism. When the users sign up, they receive a verification email. In this step, you will customize the verification email.
1. Update the resource file
On your local machine, navigate to the amplify/auth/resource.ts file, and use the following code to customize the verification email. Then, save the file.

Email verification customization code
Use this code to customize the verification email
import { defineAuth } from "@aws-amplify/backend";
export const auth = defineAuth({
loginWith: {
email: {
verificationEmailStyle: "CODE",
verificationEmailSubject: "Welcome to the ExpenseTracker!",
verificationEmailBody: (createCode) =>
`Use this code to confirm your account: ${createCode()}`,
},
},
});
2. View the customized email
This image shows an example of the customized verification email.

Set up Amplify Data
In this step, you will define the schema for the Expense data model, and use a per-owner authorization rule allow.owner() to restrict the expense record’s access to the owner of the record. Amplify will automatically add a owner: a.string() field to each expense which contains the expense owner's identity information upon record creation.
1. Update the resource file
On your local machine, navigate to the amplify/data/resource.ts file, and update the file with the following code to define the schema. Then, save the file.

Schema definition code
Use this code to define the schema
import { type ClientSchema, a, defineData } from '@aws-amplify/backend';
const schema = a.schema({
Expense: a
.model({
name:a.string(),
amount: a.float(),
})
.authorization((allow) => [allow.owner()]),
});
export type Schema = ClientSchema<typeof schema>;
export const data = defineData({
schema,
authorizationModes: {
defaultAuthorizationMode: 'userPool',
},
});
Deploy Amplify Cloud sandbox
Note: The amplify/backend.ts file is already configured to import the auth and data backend definitions. You don’t need to change it.
1. Deploy sandbox
Open a new terminal window, navigate to your app's root folder (expensetracker), and run the following command to deploy cloud resources into an isolated development space so you can iterate fast.
npx ampx sandbox

2. View confirmation message
After the cloud sandbox has been fully deployed, your terminal will display a confirmation message. This deployment will take several minutes to complete.

3. Verify output file
Verify that the amplify_outputs.json file was generated and added to your project.

Conclusion
Build the Frontend
Start Task ThreeDid you find what you were looking for today?
Let us know so we can improve the quality of the content on our pages