简体   繁体   English

如何在aws中获取creationDate小于某个值的dynamo db表的列表

[英]how to get a list of dynamo db tables in aws that have a creationDate less than a certain value

I wish to use an aws cli commad that will return a list of dynamodb tables in my aws account where the CreationDateTime is less than a certain value.我希望使用 aws cli 命令,它将在我的 aws 帐户中返回一个 dynamodb 表的列表,其中 CreationDateTime 小于某个值。 CreationDateTime is a property that is shown with the describe-table command, but the list-tables command only returns the names of the table. CreationDateTime 是一个与 describe-table 命令一起显示的属性,但 list-tables 命令只返回表的名称。 Is there any way I could possibly use a query to filter the names returned by list-tables in accordance with their corresponding CreationDateTime?有什么办法可以使用查询来根据列表表返回的名称根据它们对应的 CreationDateTime 过滤它们吗?

No - As you noted, ListTables only lists the names of tables, and there is no request that provides additional information for each table, let alone filter on such information.否 - 正如您所指出的, ListTables仅列出表的名称,并且没有为每个表提供附加信息的请求,更不用说过滤此类信息了。 You'll need to use ListTables and then DescribeTable on each of those tables.您需要在每个表上使用ListTablesDescribeTable You can run all of those DescribeTable requests in parallel to make the whole thing much faster (although there is a practical snag - to do it in parallel, you'll need to have opened a bunch of connections to the server).您可以并行运行所有这些DescribeTable请求,以使整个过程更快(尽管存在实际障碍 - 要并行执行,您需要打开一组与服务器的连接)。

As noted, the answer is simply no, the AWS CLI can not do what you want in one query.如前所述,答案是否定的,AWS CLI 无法在一个查询中执行您想要的操作。

You need to resort to shell scripting to chain the necessary aws commands, or, if you are willing to give up the hard requirement that it must be the AWS CLI, an alternative solution (and probably faster than forking off aws over and over) is to use a 5 line python script to get the result you want.您需要使用 shell 脚本来链接必要的aws命令,或者,如果您愿意放弃它必须是 AWS CLI 的硬性要求,另一种解决方案(可能比一遍又一遍地分叉aws更快)是使用 5 行 python 脚本来获得你想要的结果。 You can still run this from the command-line, but it won't be the AWS CLI specifically.您仍然可以从命令行运行它,但它不会专门是 AWS CLI。
Just perform the time arithmetic that suits your specific selection criteria.只需执行适合您特定选择标准的时间算术。

#!/usr/bin/env python3

import boto3
from datetime import datetime, timedelta, timezone

ddb = boto3.resource('dynamodb')
for t in sorted(filter(lambda table: datetime.now(timezone.utc) - table.creation_date_time < timedelta(days=90), ddb.tables.all()), key=lambda table: table.creation_date_time):
    print(f"{t.name}, {str(t.creation_date_time)}")  # tables created in the last 90 days

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM