首页 > 解决方案 > aws cli 创建一个具有生存时间规范的表

问题描述

我想执行一个 cli 命令来创建一个带有 TTL 的表。

示例云形成/无服务器

SampleTBWithTTL:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: SampleTBWithTTL
        AttributeDefinitions:
          - AttributeName: "user_id"
            AttributeType: "N"
          - AttributeName: "name"
            AttributeType: "S"
        KeySchema:
          - AttributeName: "user_id"
            KeyType: "HASH"
          - AttributeName: "name"
            KeyType: "RANGE"
        ProvisionedThroughput:
          ReadCapacityUnits: 5
          WriteCapacityUnits: 5
        TimeToLiveSpecification:
          AttributeName: expiration
          Enabled: true

所以这就是我到目前为止所拥有的:

aws dynamodb create-table --table-name sample-tb-with-ttl \
                      --attribute-definitions AttributeName=user_id,AttributeType=N \
                             AttributeName=name,AttributeType=S \
                      --key-schema AttributeName=user_id,KeyType=HASH \
                             AttributeName=name,KeyType=RANGE \
                      --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \

我想要/需要的是在我的 aws cli 命令中添加一个 TTL/TimeToLive 规范。

大佬们帮帮我谢谢!!

标签: amazon-web-servicesamazon-dynamodbaws-clittl

解决方案


首先这样做:-

aws dynamodb create-table --table-name sample-tb-with-ttl \
                  --attribute-definitions AttributeName=user_id,AttributeType=N \
                         AttributeName=name,AttributeType=S \
                  --key-schema AttributeName=user_id,KeyType=HASH \
                         AttributeName=name,KeyType=RANGE \
                  --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

然后启用 ttl :

aws dynamodb update-time-to-live --table-name sample-tb-with-ttl \
                      --time-to-live-specification Enabled=true,AttributeName=expiration

推荐阅读