aws cli 创建具有生存时间规范的 table

aws cli to create a table with a time to live specification

我想执行一个 cli 命令,它使用 TTL 创建 table。

示例云形成/无服务器

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 \

我 want/need 是在我的 aws cli 命令中添加一个 TTL/TimeToLive 规范。

大家帮帮我谢谢!!

首先这样做:-

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