Aws lambda 如何使用列表和映射创建DynamoDB表
我是DynamoDB的新手。我正在尝试用SAM项目创建DynamoDB。我知道我只能使用“S”、“N”、“B”作为AttributeType,但我想像下面这样使用Aws lambda 如何使用列表和映射创建DynamoDB表,aws-lambda,amazon-dynamodb,dynamo-local,Aws Lambda,Amazon Dynamodb,Dynamo Local,我是DynamoDB的新手。我正在尝试用SAM项目创建DynamoDB。我知道我只能使用“S”、“N”、“B”作为AttributeType,但我想像下面这样使用 { "TableName": "xyz", "KeySchema": [ { "AttributeName": "uid", "KeyType": "HASH&quo
{
"TableName": "xyz",
"KeySchema": [
{
"AttributeName": "uid",
"KeyType": "HASH"
}
],
"AttributeDefinitions": [
{
"AttributeName": "uid",
"AttributeType": "S"
},
{
"AttributeName": "email",
"AttributeType": "S"
},
{
"AttributeName": "postal_code",
"AttributeType": "S"
},
{
"AttributeName": "bookmark",
"AttributeType": "L" ← (I want to use List)
},
{
"AttributeName": "children",
"AttributeType": "M" ← (I want to use Map)
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 2,
"WriteCapacityUnits": 2
}
这是my table.json,我想用这个aws命令创建表
aws dynamodb --profile local --endpoint-url http://localhost:8000 create-table --cli-input-json file://./testdata/table.json
如何使用DynamoDB获得列表数据和地图数据?最好在向表中添加项目时进行此操作。DynamoDB有一个灵活的模式,因此不强制主键之外的模式。项目A可能有属性1,但项目B可能会忽略该属性
创建表时,只需添加主键(分区键或分区键+排序键)即可。然后使用项目所需的数据类型属性添加项目。只需知道,您不必在表定义中的项目上添加所有计划使用的属性即可。每个项目都可以有自己的属性集。一个项目唯一需要的是组成主键的那些。谢谢你的回答。你的意思是我只是在JSON中定义主键,然后在lambda上放置一个对象,该对象包含我想从代码中放入DynamoDB的所有数据?是的。DynamoDB不强制主键之外的模式。这意味着一个项目可能有属性,但另一个项目甚至没有属性。这种方式非常灵活。我可以将所有数据放入DynamoDB。谢谢