You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过AWS CLI查询创建时间早于指定值的DynamoDB表列表

筛选DynamoDB指定创建时间前的表列表方案

核心逻辑

DynamoDB的list-tables接口本身仅返回表名列表,确实需要结合describe-table接口获取每张表的CreationDateTime属性后再做筛选,直接通过AWS CLI配合基础shell命令即可实现,无需额外开发。

操作步骤

    1. 将你要对比的目标日期转换为Unix时间戳(单位:秒,CreationDateTime返回值为该格式)
      以筛选2023年1月1日0点之前创建的表为例:
      Linux 环境执行命令:date -d "2023-01-01 UTC" +%s
      macOS 环境执行命令:date -j -f "%Y-%m-%d" "2023-01-01" +%s
      执行后会输出一串数字,即为目标时间戳,比如1672531200。
    1. 执行筛选命令,将下方命令中的<目标时间戳>替换为上一步得到的数字即可
      基础版(单线程,适合表数量少的场景):
    aws dynamodb list-tables --query 'TableNames[]' --output text | tr '\t' '\n' | while read table; do
        create_time=$(aws dynamodb describe-table --table-name "$table" --query 'Table.CreationDateTime' --output text)
        if (( create_time < <目标时间戳> )); then
            echo $table
        fi
    done
    
    加速版(多线程并发,适合表数量多的场景,-P 10表示同时发起10个请求,可根据限流情况调整):
    aws dynamodb list-tables --query 'TableNames[]' --output text | tr '\t' '\n' | xargs -I {} -P 10 bash -c '
    create_time=$(aws dynamodb describe-table --table-name "{}" --query "Table.CreationDateTime" --output text)
    (( create_time < <目标时间戳> )) && echo "{}"
    '
    

注意:运行命令前请确保你的AWS CLI已配置对应账户的访问权限,且权限包含dynamodb:ListTables和dynamodb:DescribeTable操作。

内容的提问来源于stack exchange,提问作者Sabo Boz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 06:45:04