gpt4 book ai didi

amazon-web-services - 使用 CloudFormation 创建 DynamoDB 表时为什么会收到 "AttributeName cannot be empty"?

转载 作者:行者123 更新时间:2023-12-03 07:12:38 28 4
gpt4 key购买 nike

我正在尝试创建两个 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
}
}
}
}

最佳答案

您为两个表指定一个 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
}
}
]
}
}
}
}

关于amazon-web-services - 使用 CloudFormation 创建 DynamoDB 表时为什么会收到 "AttributeName cannot be empty"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69506354/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com