1

我想通過CloudFormation爲我的新創建的表啓用TTL。我試過以下無濟於事:CloudFormation - 爲DynamoDB創建TTL表創建表

{ 
    "Resources" : { 
    "mytable" : { 
     "Type" : "AWS::DynamoDB::Table", 
     "Properties" : { 
     "TableName" : "my_table", 
     "ProvisionedThroughput" : {"ReadCapacityUnits" : 1, "WriteCapacityUnits" : 5}, 
     "KeySchema" : 
     [ 
      {"AttributeName" : "user_email", "KeyType" : "HASH"}, 
      {"AttributeName" : "datetime", "KeyType" : "RANGE"} 
     ], 
     "AttributeDefinitions": [ 
      {"AttributeName" : "user_email", "AttributeType" : "S"}, 
      {"AttributeName" : "datetime", "AttributeType" : "S"} 
     ], 
     "TimeToLiveDescription": { 
      "AttributeName": "expire_at", 
      "TimeToLiveStatus": "ENABLED" 
     } 
     } 
    } 
} 

我用了TimeToLiveDescription,這是我從this doc獲得。

試圖創建堆棧給了我以下錯誤:

Encountered unsupported property TimeToLiveDescription 

回答

4

現在,DynamoDB對CloudFormation的TTL支持存在。請參閱:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-timetolivespecification.html

例子:

{ 
    "TableName": "MyTable", 
    "AttributeDefinitions": [ 
    { 
     "AttributeName": "Uid", 
     "AttributeType": "S" 
    } 
    ], 
    "KeySchema": [ 
    { 
     "AttributeName": "Uid", 
     "KeyType": "HASH" 
    } 
    ], 
    "ProvisionedThroughput": { 
    "ReadCapacityUnits": "1", 
    "WriteCapacityUnits": "1" 
    }, 
    "TimeToLiveSpecification": { 
    "AttributeName": "TimeToLive", 
    "Enabled": "TRUE" 
    } 
} 
0

這路段是針對AWS CLI的例子。

尚未將用於配置DynamoDB TTL的支持添加到雲信息中。

1

AWS的TTL Dynamo DB是一項新功能(2017年2月發佈),並且像Jared在他的回答中提到的那樣,它似乎尚未被AWS Cloudformation支持。與此同時,如果您在同一個cloudformation模板中啓動新的EC2實例,您可以執行的操作是(在UserData下)執行鏈接到的aws cli命令,將更新TTL aws dynamodb update-time-to-live --table-name TTLExample --time-to-live-specification "Enabled=true, AttributeName=ttl",從而引用你的dynamo數據庫資源(mytable)。 (還要確保實例正在使用具有必要策略的IAM角色來更新此資源)。

+0

我可以執行CLI在模板的命令,即使我不是啓動一個新的EC2實例? –

+0

需要在某種類型的主機或環境上執行CLI命令 - 因爲據我所知,另一種替代方案是通過添加執行cli命令的Lambda函數。你可以在這裏閱讀更多關於它的信息:https://alestic.com/2016/11/aws-lambda-awscli/ 我不知道任何其他方法。 – ivanji

+0

我知道的唯一其他方法(不在模板內)將使用像Jenkis這樣的構建服務/服務器來啓動Cloudformation Stack,然後從構建服務器執行必要的aws命令。 (你需要在服務器上安裝AWS cli等)。 – ivanji