为什么在使用 CloudFormation 制作 DynamoDB table 时得到 "AttributeName cannot be empty"?
Why do I get "AttributeName cannot be empty" when making a DynamoDB table using CloudFormation?
我正在尝试创建两个 DynamoDB 表。两个表都只有一个分区键,一个表有一个带有分区键和排序键的 GSI。当我尝试在 CF 中创建堆栈时,我在两个表上都收到一条错误消息,指出“属性 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
}
}
}
}
您为两个表指定了 TimeToLiveSpecification
而没有 AttributeName
,即 required per AWS docs.
Enabled
属性 存在的原因实际上是当您需要为 已启用的 TTL 更新 AttributeName
时- 在这种情况下,Enabled
字段用于首先禁用 TTL,然后允许您在重新启用 TTL 的同时更改 AttributeName
。
在您的情况下,您希望禁用 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
}
}
]
}
}
}
}
我正在尝试创建两个 DynamoDB 表。两个表都只有一个分区键,一个表有一个带有分区键和排序键的 GSI。当我尝试在 CF 中创建堆栈时,我在两个表上都收到一条错误消息,指出“属性 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
}
}
}
}
您为两个表指定了 TimeToLiveSpecification
而没有 AttributeName
,即 required per AWS docs.
Enabled
属性 存在的原因实际上是当您需要为 已启用的 TTL 更新 AttributeName
时- 在这种情况下,Enabled
字段用于首先禁用 TTL,然后允许您在重新启用 TTL 的同时更改 AttributeName
。
在您的情况下,您希望禁用 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
}
}
]
}
}
}
}