Note: This passage is written in Chinese and translated into English via ChatGPT.
I found a project tutorial for AWS Amplify on the AWS official website. It seems that it has not been translated into Chinese yet, so I took some notes while exploring it.
Introduction to AWS Amplify
Amplify is a comprehensive platform that provides static resource hosting for:
- Creating AWS backends with features like authentication, data storage, and more for web, iOS, or Android applications in minutes.
- Building frontend UI intuitively from design to code with Figma integration and connecting it to the backend with just a few clicks.
In summary, apart from a few distinctive features, it is quite similar to services like Netlify and also offers a certain amount of free usage:
- AWS Amplify Features:
- Supports visual development of full-stack websites or applications.
- Supports deploying mobile applications, which Netlify does not.
- Comprehensive ecosystem, making it convenient to use other AWS services.
Getting Started with Amplify
The main goal is to host a web page and deploy a backend, and additionally, there are examples of adding AWS authentication and storage services as supplementary features.
Note: The following steps only show the configuration and deployment process related to Amplify. The complete code of the app is not provided here. Please refer to the original article for the specific app code.
Prerequisites
- Create a frontend application or use an existing one.
- Push it to a GitHub repository.
Deploying the Frontend
- Register for an AWS account (requires a credit card that can be charged $1).
- Log in and find the AWS Management Console.
- Go to the “Get started” page and click “Get started” under the “Host your web app” section.
- Choose GitHub as the deployment option, confirm the repository and branch information, and click “Next” multiple times.
- Click “Save and deploy” to complete the process. Afterward, any modifications and pushes to the repository will automatically update the website.
Installing Amplify CLI - Adding/Managing AWS Services
Installing the CLI
Amplify CLI allows you to add AWS services to your project.
|
|
Note: Compatibility issue on ARM Macs
If you encounter issues on M1/M2 Macs, where the CLI installs successfully but commands don’t respond, you can try one of the following solutions. Refer to issue #10193 for more information:
|
|
I have successfully used the third solution, with the same environment as mentioned. It seems that it involves a translation from x86.
Configuring the CLI
|
|
You will need the CLI for adding various services. Additionally, you can now use the following command to directly access the console:
|
|
Deploying the Backend
Launching Amplify Studio
Go back to the application page - backend environments - get started - launch studio - and run the local setup command in the terminal (copy from the web page).
Then choose the configuration options:
|
|
Adding Backend Build Configuration
|
|
Example: Adding AWS Authentication
This example demonstrates how to add AWS authentication to a note-taking application.
Adding Authentication via the Command Line
|
|
Using the Auth Service in src/index.js
Import the configuration and add the following code to your src/index.js
file:
|
|
Importing Authentication into src/App.js
Import similar to the following (a sample with only authentication):
|
|
Finally, push the changes to the remote repository.
Adding a Backend Database
- Add a GraphQL API
|
|
- Local configuration
Create a schema in /amplify/backend/api/<api_name>/schema.graphql
. For example:
|
|
- Deploy the service
|
|
This will do three things:
- Create the AWS AppSync API
- Create a DynamoDB table
- Create the local GraphQL operations in a folder located at src/graphql that you can use to query the API
- Send a query in the frontend
Example:
|
|
Example: Using AWS Storage Services
This example shows how to use Amazon S3 (AWS Simple Storage Service) to store image data.
- Add the storage service
|
|
- Modify the schema
|
|
- Use storage in the app
|
|
- Deploy the service
|
|