【问题标题】:Troposphere DynamoDB TimeToLiveSpecification对流层 DynamoDB 生存时间规范
【发布时间】:2021-01-28 23:32:04
【问题描述】:

我正在尝试为新的 DynamoDB 表创建 JSON Cloudformation 模板。我正在尝试设置 TimeToLiveSpecification,但出现错误并且对流层文档不清楚。

我有

dynamoDB = t.add_resource(Table(
    "myDynamoTable",
    TableName=Join("-", [Ref(env), "dynamo-table"]),
    AttributeDefinitions=[
        AttributeDefinition(
            AttributeName=Ref(hashkeyname),
            AttributeType=Ref(hashkeytype)
        ),
        AttributeDefinition(
            AttributeName="sqsMessageId",
            AttributeType="S"
        ),
        AttributeDefinition(
            AttributeName="system",
            AttributeType="S"
        ),`enter code here`
        AttributeDefinition(
            AttributeName=Ref(sortkeyname),
            AttributeType=Ref(sortkeytype)
        ),
        AttributeDefinition(
            AttributeName="text",
            AttributeType="S"
        ),
        AttributeDefinition(
            AttributeName="ttl",
            AttributeType="N"
        )
    ],
    KeySchema=[
        KeySchema(
            AttributeName=Ref(hashkeyname),
            KeyType="HASH"
        ),
        KeySchema(
            AttributeName=Ref(sortkeyname),
            KeyType="RANGE"
        )
    ],
    TimeToLiveSpecification="WHAT GOES HERE???"
))

我什至尝试将它作为准备好的格式 JSON 放入,但它不起作用。 我试过了:

TimeToLiveSpecification=AWSProperty(AttributeName="ttl", Enabled=True)

TimeToLiveSpecification=AttributeDefinition(AttributeName="ttl", Enabled=True)

TimeToLiveSpecification=TimeToLiveSchema(AttributeName="ttl", Enabled=True)(用这个抓住稻草)。

【问题讨论】:

    标签: amazon-dynamodb amazon-cloudformation troposphere


    【解决方案1】:

    使用here 显示的 TimeToLiveSpecification 试试这个(未经测试):

    TimeToLiveSpecification=TimeToLiveSpecification(
        AttributeName="fill this in",
        Enabled=True,
    ),
    

    【讨论】:

    • 当我去部署这个时,我得到“无效的模板资源属性'AttributeName'”sigh
    • @SarahJessica 你找出问题所在了吗?我也一样。
    • 我认为这是定义了额外的属性,这些属性未在关键模式或对流层定义的其他地方使用。
    【解决方案2】:

    最后我还是去了

    ttlspec = t.add_resource(TimeToLiveSpecification(
        "ttlspec",
        AttributeName="ttl",
        Enabled=True
    ))
    

    然后

    dynamoDB = t.add_resource(Table(
        "myDynamoTable",
        TableName=Join("-", [Ref(env), "dynamo-table"]),
        AttributeDefinitions=[
            AttributeDefinition(
                AttributeName=Ref(hashkeyname),
                AttributeType=Ref(hashkeytype)
            ),
            AttributeDefinition(
                AttributeName="sqsMessageId",
                AttributeType="S"
            ),
            AttributeDefinition(
                AttributeName="system",
                AttributeType="S"
            ),`enter code here`
            AttributeDefinition(
                AttributeName=Ref(sortkeyname),
                AttributeType=Ref(sortkeytype)
            ),
            AttributeDefinition(
                AttributeName="text",
                AttributeType="S"
            ),
            AttributeDefinition(
                AttributeName="ttl",
                AttributeType="N"
            )
        ],
        KeySchema=[
            KeySchema(
                AttributeName=Ref(hashkeyname),
                KeyType="HASH"
            ),
            KeySchema(
                AttributeName=Ref(sortkeyname),
                KeyType="RANGE"
            )
        ],
        TimeToLiveSpecification=Ref(ttlspec)
    ))
    

    TimeToLiveSpecification 是一个类,需要在顶部导入。 Docs here.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多