我不知道该怎么解释:
$aws dynamodb scan --table-name Todos-dev
...
{
"Items": [
{
"todoId": {
"S": "9e6e7f0f-97ee-4289-93b9-cb1bf46d5190"
},
"createdAt": {
"S": "2019-12-29T07:11:09.581Z"
},
"name": {
"S": "test4"
},
"userId": {
和
$ aws dynamodb get-item --table-name Todos.dev --key file://key.json
An error occurred (ResourceNotFoundException) when calling the GetItem operation: Requested resource not found
其中
$ cat key.json
{"todoId": {"S": "9e6e7f0f-97ee-4289-93b9-cb1bf46d5190"}}
serverless.yml
TodosTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: todoId
AttributeType: S
- AttributeName: createdAt
AttributeType: S
- AttributeName: dueDate
AttributeType: S
KeySchema:
- AttributeName: todoId
KeyType: HASH
- AttributeName: createdAt
KeyType: RANGE
BillingMode: PAY_PER_REQUEST
TableName: ${self:provider.environment.TODOS_TABLE}
LocalSecondaryIndexes:
- IndexName: ${self:provider.environment.INDEX_NAME}
KeySchema:
- AttributeName: todoId
KeyType: HASH
- AttributeName: dueDate
KeyType: RANGE
Projection:
ProjectionType: ALL
我收到的消息“所提供的键元素与架构不匹配”,来自docClient.delete,尝试了多种组合以指定键,但没有用。
答案 0 :(得分:2)
关键元素与架构不匹配
您的表具有哈希键和范围键。您的key.json
文件只有哈希键。使用getItem
时,必须提供完整的(哈希和范围)键。如果要为同一哈希键获取多个值,或者如果范围键值未知,则只能使用哈希键,但必须使用query
API。
找不到资源
您在扫描调用中使用Todos-dev
,但在getItem调用中使用Todos.dev
。