如何使用 AWS CLI 创建 dynamodb table?

How to create a dynamodb table using AWS CLI?

我在 aws

之后尝试使用以下命令
--configure command:

aws dynamodb create-table 
--table-name MusicCollection2 
--attribute-definitions

 AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S --

key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE 

--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

Output: Nothing

请给出如何使用 AWS CLI 创建 dyanmodb table 的建议。

  1. 使用以下内容创建 JSON 文件 create-table-movies.json

    {
        "TableName": "MusicCollection2",
        "KeySchema": [
          { "AttributeName": "Artist", "KeyType": "HASH" },
          { "AttributeName": "SongTitle", "KeyType": "RANGE" }
        ],
        "AttributeDefinitions": [
          { "AttributeName": "Artist", "AttributeType": "S" },
          { "AttributeName": "SongTitle", "AttributeType": "S" }
        ],
        "ProvisionedThroughput": {
          "ReadCapacityUnits": 5,
          "WriteCapacityUnits": 5
        }
    }
    
  2. 在 DOS 命令提示符下浏览到文件路径(假设 Windows OS)并执行以下命令

在本地 DynamoDB 上创建 table:-

    aws dynamodb create-table --cli-input-json file://create-table-movies.json --endpoint-url http://localhost:8000

要在 AWS DynamoDB 服务上创建 table,请提供正确的区域名称。如果您的配置已经完成,它应该可以工作。

aws dynamodb create-table --cli-input-json file://create-table-movies.json --region us-west-2

AWS CLI 配置:-

$ aws configure
AWS Access Key ID [None]: accesskey
AWS Secret Access Key [None]: secretkey
Default region name [None]: us-west-2
Default output format [None]:

执行上述命令后,它会更新您个人资料中的数据(windows)。

C:\Users\<username>\.aws\

检查以下文件:-

config   - should have the region name
credentials  - should have access key and secret key

凭证样本:-

[default]
aws_access_key_id = aaaadffewe
aws_secret_access_key = t45435egfdg456retgfg

配置文件示例:-

[default]
region = us-east-1