amazon-web-services - 为什么使用 CloudFormation 制作 DynamoDB 表时出现“AttributeName 不能为空”?
问题描述
我正在尝试创建两个 DynamoDB 表。两个表都只有一个分区键,一个表有一个 GSI,它带有一个分区键和一个排序键。当我尝试在 CF 中创建堆栈时,我在两个表上都收到一条错误消息,指出“Property AttributeName 不能为空。”。但是,我相信我已经为我的每个键值提供了 AttributeName。我也将模板转换为 JSON,但我得到了同样的错误。我哪里错了?请注意,这不是完整的模板,只是导致错误的部分。首先十分感谢!
YAML 配置:
DynamoDBTable:
Type: "AWS::DynamoDB::Table"
Properties:
AttributeDefinitions:
-
AttributeName: "eventName"
AttributeType: "S"
TableName: "BlockCursorTable"
Tags:
-
Key: "project"
Value: "flow-event-monitor"
KeySchema:
-
AttributeName: "eventName"
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TimeToLiveSpecification:
Enabled: false
DynamoDBTable2:
Type: "AWS::DynamoDB::Table"
Properties:
AttributeDefinitions:
-
AttributeName: "listingResourceID"
AttributeType: "N"
-
AttributeName: "staticKey"
AttributeType: "N"
-
AttributeName: "timestamp"
AttributeType: "S"
TableName: "ListingTable"
Tags:
-
Key: "project"
Value: "flow-event-monitor"
KeySchema:
-
AttributeName: "listingResourceID"
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
GlobalSecondaryIndexes:
-
IndexName: "staticKey-timestamp-index"
KeySchema:
-
AttributeName: "staticKey"
KeyType: "HASH"
-
AttributeName: "timestamp"
KeyType: "RANGE"
Projection:
ProjectionType: "ALL"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TimeToLiveSpecification:
Enabled: false
等效的 JSON 模板:
{
"DynamoDBTable": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"AttributeDefinitions": [
{
"AttributeName": "eventName",
"AttributeType": "S"
}
],
"TableName": "BlockCursorTable",
"Tags": [
{
"Key": "project",
"Value": "flow-event-monitor"
}
],
"KeySchema": [
{
"AttributeName": "eventName",
"KeyType": "HASH"
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
},
"TimeToLiveSpecification": {
"Enabled": false
}
}
},
"DynamoDBTable2": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"AttributeDefinitions": [
{
"AttributeName": "listingResourceID",
"AttributeType": "N"
},
{
"AttributeName": "staticKey",
"AttributeType": "N"
},
{
"AttributeName": "timestamp",
"AttributeType": "S"
}
],
"TableName": "ListingTable",
"Tags": [
{
"Key": "project",
"Value": "flow-event-monitor"
}
],
"KeySchema": [
{
"AttributeName": "listingResourceID",
"KeyType": "HASH"
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
},
"GlobalSecondaryIndexes": [
{
"IndexName": "staticKey-timestamp-index",
"KeySchema": [
{
"AttributeName": "staticKey",
"KeyType": "HASH"
},
{
"AttributeName": "timestamp",
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
}
}
],
"TimeToLiveSpecification": {
"Enabled": false
}
}
}
}
解决方案
您为两个表指定 a TimeToLiveSpecification
with no ,这是AWS 文档所必需的。AttributeName
该属性存在的原因Enabled
实际上是当您需要AttributeName
为已启用的 TTL更新时- 在这种情况下,该Enabled
字段用于首先禁用 TTL,然后允许您AttributeName
在重新启用的同时更改TTL。
在您的情况下,您希望禁用 TTL。
默认情况下禁用生存时间,因此请随意从 CloudFormation 模板中删除这些部分,因为它们不起作用。
我在Resources
下面包含了一个部分以允许您进行测试(考虑到您只共享了模板的一部分)。
这应该有效:
{
"Resources":{
"DynamoDBTable":{
"Type":"AWS::DynamoDB::Table",
"Properties":{
"AttributeDefinitions":[
{
"AttributeName":"eventName",
"AttributeType":"S"
}
],
"TableName":"BlockCursorTable",
"Tags":[
{
"Key":"project",
"Value":"flow-event-monitor"
}
],
"KeySchema":[
{
"AttributeName":"eventName",
"KeyType":"HASH"
}
],
"ProvisionedThroughput":{
"ReadCapacityUnits":1,
"WriteCapacityUnits":1
}
}
},
"DynamoDBTable2":{
"Type":"AWS::DynamoDB::Table",
"Properties":{
"AttributeDefinitions":[
{
"AttributeName":"listingResourceID",
"AttributeType":"N"
},
{
"AttributeName":"staticKey",
"AttributeType":"N"
},
{
"AttributeName":"timestamp",
"AttributeType":"S"
}
],
"TableName":"ListingTable",
"Tags":[
{
"Key":"project",
"Value":"flow-event-monitor"
}
],
"KeySchema":[
{
"AttributeName":"listingResourceID",
"KeyType":"HASH"
}
],
"ProvisionedThroughput":{
"ReadCapacityUnits":1,
"WriteCapacityUnits":1
},
"GlobalSecondaryIndexes":[
{
"IndexName":"staticKey-timestamp-index",
"KeySchema":[
{
"AttributeName":"staticKey",
"KeyType":"HASH"
},
{
"AttributeName":"timestamp",
"KeyType":"RANGE"
}
],
"Projection":{
"ProjectionType":"ALL"
},
"ProvisionedThroughput":{
"ReadCapacityUnits":1,
"WriteCapacityUnits":1
}
}
]
}
}
}
}
推荐阅读
- c# - 当我单击按钮时,如何在另一个页面上调用 void?
- swift - 从 Swift 5 中的 firebase 实时数据库返回一个 int
- c# - 有没有办法在 C# 的部分类中编写相同的属性名称?
- jquery - jQuery 按按钮类显示和隐藏 div
- vue.js - 根据响应中收到的值动态更改项目的图标
- node.js - Ember js - 无法使用 urlFor 方法生成带有动态段的 URL
- python - 应该检查每个数字并得到错误的输出
- http - 存在哪些类型的返回媒体文件(图像、视频和其他)的响应,以及何时使用它们
- javascript - Map() 菜单项。如何范围选择菜单项?
- c - 将金丝雀用于 bss 或数据部分以检测溢出/粉碎有用吗?