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

查看:264
本文介绍了如何通过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.

推荐答案

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

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.

另一种选择是 DynamoDBtoCSV 项目位于github。

Another option is the DynamoDBtoCSV project at github.

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

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