如何使用 AWS CLI 创建 dynamodb 表? [英] How to create a dynamodb table using AWS CLI?
问题描述
我在 aws 之后尝试以下命令
--configure 命令:aws dynamodb 创建表--table-name MusicCollection2--属性定义AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S --键模式 AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
<块引用>
输出:无
请建议如何使用 AWS CLI 创建 dyanmodb 表.
使用以下内容创建 JSON 文件
create-table-movies.json
<代码>{"TableName": "MusicCollection2",密钥架构":[{ "AttributeName": "Artist", "KeyType": "HASH" },{ "AttributeName": "SongTitle", "KeyType": "RANGE" }],属性定义":[{ "AttributeName": "Artist", "AttributeType": "S" },{ "AttributeName": "SongTitle", "AttributeType": "S" }],预配吞吐量":{"ReadCapacityUnits": 5,写入容量单位":5}}
在 DOS 命令提示符(假设为 Windows 操作系统)上浏览到文件路径并执行以下命令
在本地 DynamoDB 上创建表:-
aws dynamodb create-table --cli-input-json file://create-table-movies.json --endpoint-url http://localhost:8000
要在 AWS DynamoDB 服务上创建表,请提供正确的区域名称.如果您的配置已经完成,它应该可以工作.
aws dynamodb create-table --cli-input-json file://create-table-movies.json --region us-west-2
AWS CLI 配置:-
$ aws 配置AWS 访问密钥 ID [无]:访问密钥AWS 秘密访问密钥 [无]:secretkey默认区域名称 [无]:us-west-2默认输出格式 [无]:
执行上述命令后,它会更新您的个人资料(在 Windows 上)上的数据.
C:\Users\<用户名>\.aws\
检查以下文件:-
config - 应该有区域名称凭证 - 应该有访问密钥和秘密密钥
凭据示例:-
[默认]aws_access_key_id = aaaadffeweaws_secret_access_key = t45435egfdg456retgfg
配置文件示例:-
[默认]地区 = us-east-1
I am trying below command after 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
Please give suggestion how to create dyanmodb table using AWS CLI.
Create the JSON file
create-table-movies.json
with the below content{ "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 } }
Browse to the file path on DOS command prompt (assuming Windows OS) and execute the below command
Creates the table on local DynamoDB:-
aws dynamodb create-table --cli-input-json file://create-table-movies.json --endpoint-url http://localhost:8000
To create the table on AWS DynamoDB service, please provide the correct region name. If your config is done already, it should work.
aws dynamodb create-table --cli-input-json file://create-table-movies.json --region us-west-2
AWS CLI Configure:-
$ 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]:
Once you execute the above command, it updates the data on your profile (on windows).
C:\Users\<username>\.aws\
Check the following files:-
config - should have the region name
credentials - should have access key and secret key
Credentials Sample:-
[default]
aws_access_key_id = aaaadffewe
aws_secret_access_key = t45435egfdg456retgfg
Config File Sample:-
[default]
region = us-east-1
这篇关于如何使用 AWS CLI 创建 dynamodb 表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!