あめがえるのITブログ

頑張りすぎない。ほどほどに頑張るブログ。

AWS AmplifyのBackend(Storage(DynamoDB))を作成してみた


やること

AmplifyでDynamoDBを作成する

前提

コマンド実行環境はWindows11を使用

実践!

1.DynamoDB作成
1-1.PowerShellを開く
1-2.Amplifyのローカルフォルダへ移動
1-3.下記を実行

> amplify add storage
> amplify add storage
? Select from one of the below mentioned services: NoSQL Database ★NoSQLを選択

Welcome to the NoSQL DynamoDB database wizard
This wizard asks you a series of questions to help determine how to set up your NoSQL database table.

√ Provide a friendly name · dynamo3c6a94e5 ★デフォルトの名前を使用
√ Provide table name · dynamo3c6a94e5 ★デフォルトの名前を使用

You can now add columns to the table.

√ What would you like to name this column · aaa ★適当な名前のカラムを作成
√ Choose the data type · string ★カラムの属性を文字列に指定
√ Would you like to add another column? (Y/n) · no ★他追加はしないので、[No]

Before you create the database, you must specify how items in your table are uniquely organized. You do this by specifying a primary key. The primary key uniquely identifies each item in the table so that no two items can have the same key. This can be an individual column, or a combination that includes a primary key and a sort key.

To learn more about primary keys, see:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.PrimaryKey

Only one option for [Choose partition key for the table]. Selecting [aaa].
√ Do you want to add a sort key to your table? (Y/n) · no ★ソートキーはいったん作らないので、[No]

You can optionally add global secondary indexes for this table. These are useful when you run queries defined in a different column than the primary key.
To learn more about indexes, see:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.SecondaryIndexes

√ Do you want to add global secondary indexes to your table? (Y/n) · no  ★グローバルセカンダリーインデックスは作成しないので、[No]
√ Do you want to add a Lambda Trigger for your Table? (y/N) · no ★Lambdaのトリガーは設定しないので、[No]
✅ Successfully added resource dynamo3c6a94e5 locally

⚠️ If a user is part of a user pool group, run "amplify update storage" to enable IAM group policies for CRUD operations
✅ Some next steps:
"amplify push" builds all of your local backend resources and provisions them in the cloud
"amplify publish" builds all of your local backend and front-end resources (if you added hosting category) and provisions them in the cloud

1-4.下記を実行

> amplify push
> amplify push
√ Successfully pulled backend environment dev from the cloud.

    Current Environment: dev

┌──────────┬─────────────────┬───────────┬───────────────────┐
│ Category │ Resource name   │ Operation │ Provider plugin   │
├──────────┼─────────────────┼───────────┼───────────────────┤
│ Storage  │ dynamo3c6a94e5  │ Create    │ awscloudformation │
├──────────┼─────────────────┼───────────┼───────────────────┤
│ Function │ amplify6d148998 │ No Change │ awscloudformation │
├──────────┼─────────────────┼───────────┼───────────────────┤
│ Api      │ api9bb60a4c     │ No Change │ awscloudformation │
└──────────┴─────────────────┴───────────┴───────────────────┘
√ Are you sure you want to continue? (Y/n) · yes

Deployment completed.
Deployed root stack amplify [ ======================================== ] 4/4
        amplify-amplify-dev-5fd03      AWS::CloudFormation::Stack     UPDATE_COMPLETE                Sun Jun 09 2024
        storagedynamo3c6a94e5          AWS::CloudFormation::Stack     CREATE_COMPLETE                Sun Jun 09 2024
        functionamplify6d148998        AWS::CloudFormation::Stack     UPDATE_COMPLETE                Sun Jun 09 2024
        apiapi9bb60a4c                 AWS::CloudFormation::Stack     UPDATE_COMPLETE                Sun Jun 09 2024
Deployed storage dynamo3c6a94e5 [ ======================================== ] 1/1
        DynamoDBTable                  AWS::DynamoDB::Table           CREATE_COMPLETE                Sun Jun 09 2024

Deployment state saved successfully.


2.作成確認
2-1.[AWS] - [DynamoDB]- [テーブル]

2-2.DynamoDBのデータベースが作成されていること


感想

CloudFormationで十分な気がする。
※裏でCloudFormationが動いているから余計に。。。