【发布时间】:2019-02-23 21:40:24
【问题描述】:
我有一张这样的桌子
account_id email deactivation_date deleted_on
1 test1@test.com 2018-09-26T16:28:41.143Z NULL
2 test2@test.com 2018-09-19T16:28:41.143Z 2018-09-19T16:28:41.143Z
我正在使用 AWS CLI 填充测试数据,如图所示,如果已停用,deleted_on 字段将为 null 或具有字符串。
我正在使用 cloudformation 模板来构建索引,但它一直失败。 我想在 deactivation_date 上建立一个索引,以便我可以查询 检索所有帐户
deactivation_date < tomorrow, and deleted_on is null
这是我的 cft
AttributeDefinitions:
- AttributeName: "account_id"
AttributeType: "S"
- AttributeName: "email"
AttributeType: "S"
- AttributeName: "deactivation_date"
AttributeType: "S"
KeySchema:
-
AttributeName: "account_id"
KeyType: "HASH"
GlobalSecondaryIndexes:
- IndexName: "email-index"
KeySchema:
- AttributeName: "email"
KeyType: "HASH"
Projection:
ProjectionType: "ALL"
ProvisionedThroughput:
ReadCapacityUnits: !If [conditionIsProd, 10, 5]
WriteCapacityUnits: !If [conditionIsProd, 10, 5]
- IndexName: "deactivation_date-index"
KeySchema:
- AttributeName: "deactivation_date"
KeyType: "RANGE"
Projection:
ProjectionType: "ALL"
ProvisionedThroughput:
ReadCapacityUnits: !If [conditionIsProd, 10, 5]
WriteCapacityUnits: !If [conditionIsProd, 10, 5]
它一直在抱怨
无效的 KeySchema:第一个 KeySchemaElement 不是 HASH 键类型(服务:AmazonDynamoDBv2;状态代码:400;错误代码:ValidationException;请求 ID:xxxxxxx)
如果我把 deleted_on 作为索引, 比如
- AttributeName: "deleted_on"
AttributeType: "S"
它会抱怨因为我试图插入 NULL,但是如果我这样做了
- AttributeName: "deleted_on"
AttributeType: NULL
它还会抱怨我试图添加字符串。
我不确定这样做的正确方法是什么
【问题讨论】:
标签: database amazon-web-services aws-lambda amazon-dynamodb aws-sdk