I'm trying to create two DynamoDB tables. Both tables have just one partition key, and one has a GSI with a partition key and a sort key. When I try and create the stack in CF, I receive an error on both tables stating that "Property AttributeName cannot be empty.". However, I believe I have provided AttributeName for each of my key values. I have converted the template to JSON as well, yet I get the same error. Where am I going wrong? Please note that this is not the complete template, only the part that is causing an error. Thanks very much in advance!
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
EDIT
I have added the JSON CF template below as well:
{
"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
}
}
}
}
CodePudding user response:
You're specifying a TimeToLiveSpecification
with no AttributeName
for both tables, which is required per AWS docs.
The reason why the Enabled
property exists, is actually for when you need to update the AttributeName
for an already enabled TTL - in that case, the Enabled
field is used to first disable the TTL to then allow you to change the AttributeName
at the same time you re-enable TTL.
In your case, you want TTL disabled.
Time to Live is disabled by default, so feel free to remove those sections from your CloudFormation template as they take no effect.
I’ve included a Resources
section below to allow you to test (considering you’ve only shared a part of your template).
This should work:
{
"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
}
}
]
}
}
}
}