如何通过 aws-cli 将 dynamodb 表导出为 csv(不使用管道) [英] How to export a dynamodb table as a csv through aws-cli ( without using pipeline)

查看:31
本文介绍了如何通过 aws-cli 将 dynamodb 表导出为 csv(不使用管道)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 aws-cli 的新手,我正在尝试将我的 dynamodb 表导出为 csv,以便可以将其直接导入 postgresql.有没有办法使用 aws-cli 做到这一点?

I am new to aws-cli and I am trying to export my dynamodb table as a csv so that i can import it directly into postgresql. Is there a way to do that using aws-cli ?

到目前为止,我遇到了这个命令 aws dynamodb scan --table-name .但这不提供 csv 导出选项.此外,通过此命令,我可以在命令提示符下获得输出,但我不确定如何将其写入文件.

So far i have came across this command aws dynamodb scan --table-name . But this does not provide an option of a csv export. Also, through this command I can get the output on my command prompt but I am not sure how to write it in a file.

推荐答案

如果所有项目都具有相同的属性,例如idname 都是字符串,然后运行:

If all items have the same attributes, e.g. id and name both of which are strings, then run:

aws dynamodb scan 
    --table-name mytable 
    --query "Items[*].[id.S,name.S]" 
    --output text

这将提供制表符分隔的输出.您可以使用 > 将此重定向到文件.output.txt,然后您可以轻松地将制表符转换为 csv 的逗号.

That would give tab-separated output. You can redirect this to file using > output.txt, and you could then easily convert tabs into commas for csv.

请注意,您可能需要根据 扫描文档进行分页:

Note that you may need to paginate per the scan documentation:

如果扫描项目的总数超过最大数据集大小限制 1 MB,则扫描停止并将结果作为 LastEvaluatedKey 值返回给用户,以便在后续操作中继续扫描.结果还包括超出限制的项目数.扫描可能导致没有符合过滤条件的表数据.

If the total number of scanned items exceeds the maximum dataset size limit of 1 MB, the scan stops and results are returned to the user as a LastEvaluatedKey value to continue the scan in a subsequent operation. The results also include the number of items exceeding the limit. A scan can result in no table data meeting the filter criteria.

另一个选择是 github 上的 DynamoDBtoCSV 项目.

Another option is the DynamoDBtoCSV project at github.

这篇关于如何通过 aws-cli 将 dynamodb 表导出为 csv(不使用管道)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆