通过 JavaScript 访问 Amazon DynamoDB 上的数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9180398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 05:50:36  来源:igfitidea点击:

Accessing data on Amazon's DynamoDB via JavaScript

javascriptnode.jsamazon-web-servicesamazon-dynamodb

提问by rafidude

1) Client Access: Is there anyway to perform CRUD operations on DynamoDB using client side JavaScript (REST/Ajax/jQuery)?

1) 客户端访问:无论如何要使用客户端 JavaScript (REST/Ajax/jQuery) 在 DynamoDB 上执行 CRUD 操作?

I know Amazon has support for .NET and Java.

我知道亚马逊支持 .NET 和 Java。

2) Server Access: Is there any way we can access DynamoDB using server side JavaScript (Node.js) without having to install Java/.NET on the server?

2)服务器访问:有什么方法可以使用服务器端JavaScript(Node.js)访问DynamoDB,而无需在服务器上安装Java/.NET?

回答by Steffen Opel

Update 2012-12-05

更新 2012-12-05

There is now an official AWS SDK for Node.js, see the introductory post AWS SDK for Node.js - Now Available in Preview Formfor details, here are the initially supported services:

现在有一个适用于 Node.js的官方AWS 开发工具包,请参阅介绍性文章适用于 Node.jsAWS 开发工具包 - 现在以预览形式提供详细信息,以下是最初支持的服务:

The SDK supports Amazon S3, Amazon EC2, Amazon DynamoDB, and the Amazon Simple Workflow Service, with support for additional services on the drawing board. [emphasis mine]

该开发工具包支持Amazon S3Amazon EC2Amazon DynamoDBAmazon Simple Workflow Service,并支持绘图板上的其他服务。[强调我的]



Update 2012-02-27

更新 2012-02-27

Wantworthyhas implemented a Node.jsmodule for accessing Amazon DynamoDBa week after its launch date, thus covering 2) as well, see dynode:

Wantworthy已经实现了一个Node.js模块,用于在其发布日期后一周访问Amazon DynamoDB,因此也涵盖了 2),参见dynode

Dynode is designed to be a simple and easy way to work with Amazon's DynamoDB service. Amazon's http api is complicated and non obvious how to interact with it. This client aims to offer a simplified more obvious way of working with DynamoDB, but without getting in your way or limiting what you can do with DynamoDB.

Dynode 旨在成为一种使用亚马逊 DynamoDB 服务的简单易行的方式。亚马逊的 http api 很复杂,而且如何与之交互并不明显。该客户端旨在提供一种简化的更明显的 DynamoDB 工作方式,但不会妨碍您或限制您可以使用 DynamoDB 执行的操作。



Update 2012-02-11

更新 2012-02-11

Peng Xiehas implemented a Node.jsmodule for accessing Amazon DynamoDBat its launch date basically, thus covering 2) already, see dynamoDB:

Peng Xie已经实现了一个Node.js模块,用于在发布日期访问Amazon DynamoDB基本上,因此已经涵盖了 2),参见dynamoDB

DynamoDB uses JSON for communication. [...] This module wraps up the request and takes care of authentication. The user will be responsible for crafting the request and consuming the result.

DynamoDB 使用 JSON 进行通信。[...] 该模块包装请求并处理身份验证。用户将负责制作请求并使用结果。



Unfortunately there is no official/complete JavaScript SDK for AWS as of today (see AWS Software Development Kitsand boto [Python]for the available offerings).

不幸的是,截至今天,还没有适用于 AWS 的官方/完整 JavaScript开发工具包(有关可用产品,请参阅AWS 软件开发工具包boto [Python])。

Fortunately decent coverage for several AWS services in JavaScript is provided by the Node.js library aws-libalready though, which would be a good starting point for adding DynamoDB accordingly. An as of today unresolved feature request to Add support for DynamoDBhas been filed already as well.

幸运的是,Node.js 库aws-lib已经为 JavaScript 中的几个 AWS 服务提供了不错的覆盖,这将是相应地添加 DynamoDB 的一个很好的起点。截至今天,尚未解决的添加对 DynamoDB 支持的功能请求也已提交。

Further, AWS forum user gmlvsk3has recently implemented dedicated JavaScript interface for DynamoDB, but supposedly you need [a] Java runtime to run it, because it is based on the Mozilla RhinoJavaScript engine - I haven't reviewed the code in detail yet (at first sight it looks a bit immature though in comparison to e.g. aws-lib, but may cover your needs regardless of course), so you should check it out yourself.

此外,AWS 论坛用户gmlvsk3最近为 DynamoDB实现了专用的JavaScript 接口,但据说您需要 [a] Java 运行时来运行它,因为它基于Mozilla RhinoJavaScript 引擎 - 我还没有详细代码(乍一看,虽然与aws-lib相比,它看起来有点不成熟,但无论如何都可以满足您的需求),因此您应该自己检查一下。

Finally, you can implement JavaScript HTTP Requests to Amazon DynamoDByourself of course (see the API Reference for Amazon DynamoDBfor details):

最后,您当然可以自己实现对 Amazon DynamoDB 的JavaScript HTTP 请求(有关详细信息,请参阅Amazon DynamoDBAPI 参考):

If you don't use one of the AWS SDKs, you can perform Amazon DynamoDB operations over HTTP using the POST request method. The POST method requires you to specify the operation in the header of the request and provide the data for the operation in JSON format in the body of the request.

如果您不使用 AWS 开发工具包之一,则可以使用 POST 请求方法通过 HTTP 执行 Amazon DynamoDB 操作。POST 方法要求您在请求的标头中指定操作,并在请求正文中以 JSON 格式提供操作的数据。

回答by rafidude

I created a module called Dinoto make it easier to work with the AWS SDK in web applications. You can use something like Restifyto expose your data to jQuery via a REST interface.

我创建了一个名为Dino的模块,以便更轻松地在 Web 应用程序中使用 AWS 开发工具包。您可以使用Restify 之类的工具通过 REST 接口将数据公开给 jQuery。

Suppose you wanted to display pages of blog posts for a user. Using Dino and Restify, you would do the following:

假设您想为用户显示博客文章页面。使用 Dino 和 Restify,您将执行以下操作:

server.get('/posts/:user_id', function(req, res, next){
    Post.find({
        match: {
            user_id: req.params.user_id
        },
        skip: req.params.skip || 0,
        take: req.params.take || 10
    }, function(err, posts){
        return res.send(posts.toJSON());
    });
});

回答by Ken Lin

Regarding 1), there is now the AWS SDK for JavaScript in the Browserthat allows you to access services including DynamoDB.

关于 1),现在浏览器中适用于 JavaScriptAWS 开发工具包,允许您访问包括DynamoDB在内的服务

回答by spolu

as for 2) we've been working as well since DDB launch date. One of its key features are simplicity/performance and how close it is (retry behavior, etc) to Amazon official Java/PHP libraries:

至于 2) 自 DDB 发布之日起,我们也一直在工作。它的主要特性之一是简单性/性能以及它与亚马逊官方 Java/PHP 库的接近程度(重试行为等):

https://github.com/teleportd/node-dynamodb

https://github.com/teleportd/node-dynamodb

It's successfully used in production at various places with 100+ write/s (at teleportd). Additionally we're working on a a mocked version to enable efficient testing of the library's client code.

它以 100+ 次写入/秒(在传送时)成功地用于生产中的各个地方。此外,我们正在开发一个模拟版本,以实现对库客户端代码的有效测试。