希望实现【AWS】API Gateway→Lambda→AppSync→DynamoDB,同时加入Amplify的方案 – 第三部分.
请点击此处查看之前的文章(第一部分)。
我们继续做下去吧。
本次的目标范围

前提条件- 前提
-
- AWSのアカウントがあること
-
- Amplicy Cliをインストールしていること(筆者バージョン:11.0.2)
- 「amplify configure」コマンドを実行していること
创建Amplify项目
首先,我們將創建一個與上一次類似的Amplify項目。
$ amplify init
Note: It is recommended to run this command from the root of your app directory
? Enter a name for the project backendApp
The following configuration will be applied:
Project information
| Name: backendApp
| Environment: dev
| Default editor: Visual Studio Code
| App type: javascript
| Javascript framework: none
| Source Directory Path: src
| Distribution Directory Path: dist
| Build Command: npm.cmd run-script build
| Start Command: npm.cmd 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 [.aws/credentialsのprofile名]
Adding backend environment dev to AWS Amplify app: ********
~~~
Deployment state saved successfully.
√ Initialized provider successfully.
✅ Initialized your environment successfully.
Your project has been successfully initialized and connected to the cloud!
添加AppSync(DynamoDB)
接下来,我们将添加AppSync(通过添加AppSync,将自动创建DynamoDB表)。
$ amplify add api
╭────────────────────────────────────────────────────────────╮
│ │
│ Update available: │
│ Run amplify upgrade for the latest features and fixes! │
│ │
╰────────────────────────────────────────────────────────────╯
? Select from one of the below mentioned services: GraphQL
? Here is the GraphQL API that we will create. Select a setting to edit or continue Continue
? Choose a schema template: Single object with fields (e.g., “Todo” with ID, name, description)
⚠️ WARNING: your GraphQL API currently allows public create, read, update, and delete access to all models via an API Key. To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql/authorization-rules
✅ GraphQL schema compiled successfully.
Edit your schema at C:\Users\ShingoYoshimatsu\develop\amplify\backend\api\backendapp\schema.graphql or place .graphql files in a directory at C:\amplify\backend\api\backendapp\schema
√ Do you want to edit the schema now? (Y/n) · yes
Edit the file in your editor: C:\amplify\backend\api\backendapp\schema.graphql
✅ Successfully added resource backendapp locally
✅ Some next steps:
"amplify push" will build all your local backend resources and provision it in the cloud
"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud
这样做的话,\amplify\backend\api\backendapp\schema.graphql将会自动生成。
通过编辑这个schema.graphql文件,可以将更改反映到DynamoDB的表中。
# This "input" configures a global authorization rule to enable public access to
# all models in this schema. Learn more about authorization rules here: https://docs.amplify.aws/cli/graphql/authorization-rules
input AMPLIFY { globalAuthRule: AuthRule = { allow: public } } # FOR TESTING ONLY!
type Todo @model {
id: ID!
name: String!
description: String
}
将资料同步到AWS

执行以下命令。
$ amplify push
您可以将资料反映到AWS云上。
继续下次。