为什么在使用 CloudFormation 创建 DynamoDB 表时会出现"AttributeName cannot be empty"?



我试图创建两个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
}
}
}
}

您正在为两个表指定一个没有AttributeNameTimeToLiveSpecification,这是每个AWS文档所要求的。

Enabled属性存在的原因,实际上是当您需要更新AttributeName已经启用的TTL-在这种情况下,Enabled字段用于首先禁用TTL,然后允许您在重新启用TTL的同时更改AttributeName

在您的例子中,您想要禁用TTL。

Time to Live默认情况下是禁用的,所以可以随意从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
}
}
]
}
}
}
}

相关内容

最新更新