对AWS DynamoDB的r语言支持 [英] r language support for AWS DynamoDB

查看:130
本文介绍了对AWS DynamoDB的r语言支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对此的跟进/更新问题:

This is a follow up / updated question to this:

AWS dynamodb support for "R" programming language

我正在寻找有关如何将表从DynamoDB读入R的示例或文档。

I am looking for examples or documentation on how to read in a table from DynamoDB into R.

这个问题为我指明了正确的方向:

This question pointed me in the right direction:

R + httr和EC2 api身份验证问题

(由伟大的@hadley亲自回答!)。

(answered by the great @hadley himself!).

如果我必须先使用httr然后解析json响应,那是可以的,但是我什至不知道如何格式化POST请求。

It's ok if I have to use httr and then parse a json response, but I can't even figure out how to format the POST request.

谢谢!

推荐答案

从< a href = https://stackoverflow.com/a/43719043/7947081>此处,因为有人向我发送此页面询问类似问题。

Repeating my answer from here since someone sent me this page asking a similar question.

这是我用来将DynamoDB中的数据读取到R中的简化版本。它依赖于R和Python可以交换数据的事实,以及一个名为 boto 可以非常轻松地从DynamoDB获取数据。如果这全部是R软件包,那就很好了,但是考虑到您可以从Amazon获得25GB的免费存储空间,我不会抱怨。

Here's a simplified version of what I'm using for reading data from DynamoDB into R. It relies on the fact that R and Python can exchange data, and a library called boto in Python makes it really easy to get data from DynamoDB. It would be neat if this was all an R package, but I won't complain given the 25GB of free storage you can get from Amazon.

首先,您需要一个像这样的Python脚本 query_dynamo.py

First, you need a Python script like so named query_dynamo.py:

import boto3
import time

dynamodb = boto3.resource('dynamodb',
                          aws_access_key_id='<GET ME FROM AWS>',
                          aws_secret_access_key='<ALSO GET ME FROM AWS CONSOLE>',
                          region_name='us-east-1')

table = dynamodb.Table('comment')  ###Your table name in DynamoDB here

response = table.scan()
data = response['Items']

while 'LastEvaluatedKey' in response:
    response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
    data.extend(response['Items'])

然后在R中做这个。如果您要在Windows上尝试此操作,则可能需要尝试 rPython-win 。我在Ubuntu Linux 16.04 LTS上完成了所有这些操作。

Then in R you do this. If you're trying this on Windows, you may want to try rPython-win instead. I did all this on Ubuntu Linux 16.04 LTS.

library(rPython)


python.load("query_dynamo.py")
temp = as.data.frame(python.get('data'))
df = as.data.frame(t(temp))
rm(temp)

现在您将拥有一个名为 df的数据框,其内容为无论您在DynamoDB中放入什么。

Now you'll have a dataframe called "df" with the contents of whatever you put in DynamoDB.

这篇关于对AWS DynamoDB的r语言支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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