5

我最近阅读了有关 Amazon 的新数据库产品 DynamoDB,并且必须承认它听起来非常引人注目。然而,在我跑掉并开始重新编程我的模型层以利用块上的新孩子之前,我需要一些更多的细节。有谁知道抽象 DynamoDB 的 Perl 包还是太早了?我将其称为“ORM”包,但在 DynamoDB 世界中没有任何关系。alpha,beta中是否有一个?如何通过 Perl 访问亚马逊的 dynamodb?

谢谢

4

3 回答 3

4

您还可以使用我的 perl 模块 Net::Amazon::DynamoDB(@MadHacker:我冒昧地修改了您上面的签名代码)。

于 2012-03-14T12:50:19.363 回答
0

我用 JavaScript 编写了 DynamoDB 的接口 我也是 Perl 程序员 请看提供的示例,它与 Perl 非常相似

在此处查看示例和下载链接

于 2012-01-24T05:45:07.383 回答
0

这是一个如何使用 perl 进行操作的示例

#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;
use Net::Amazon::AWSSign;
use XML::XPath;
use XML::XPath::XMLParser;

use LWP::UserAgent;

use HTTP::Request::Common;
use DateTime::Format::HTTP;
use Digest::SHA qw(sha256 hmac_sha256_base64);
use URI::Escape;

my $iam_key_id = 'Your AWS Access Key';
my $iam_secret = 'Your Security tocken';

my $url = "https://sts.amazonaws.com/?" .
"Action=GetSessionToken" .
"&Version=2011-06-15";

my $awsSign = new Net::Amazon::AWSSign("$iam_key_id", "$iam_secret"); # New object
my $awsSignedRESTURI = $awsSign->addRESTSecret($url); # Returns signed REST query URI for lwp-get, curl, etc.

my $response = `curl -s "$awsSignedRESTURI"`;
print Dumper($response);

my $xp = XML::XPath->new(xml => $response);
$xp->set_namespace('xx','https://sts.amazonaws.com/doc/2011-06-15/');   
my $sessionToken = $xp->getNodeText('/xx:GetSessionTokenResponse/GetSessionTokenResult/Credentials/SessionToken');
my $accessKeyId = $xp->getNodeText('/xx:GetSessionTokenResponse/GetSessionTokenResult/Credentials/AccessKeyId');
my $secretAccessKey = $xp->getNodeText('/xx:GetSessionTokenResponse/GetSessionTokenResult/Credentials/SecretAccessKey');
print $sessionToken . "\n";

#   SESSION TOKEN RECEIVED

put('{"TableName":"Test","Item":{"Id":{"S":"1"},"name":{"S":"somedata"}}}');
print "-----------------------------\n";
get('{"TableName":"Test","Key":{"HashKeyElement":{"S":"1"}}}');

exit;


sub get
{
  my ($json) = @_;

  perform('GetItem', $json);
}

sub put
{
  my ($json) = @_;

  perform('PutItem', $json);
}

sub perform
{
  my ($target, $json) = @_;

  my $class = 'DateTime::Format::HTTP';
  my $date = $class->format_datetime(DateTime->now);

  my $tosign =
    "POST\n" .
    "/\n" .
    "\n" .
    "host:dynamodb.us-east-1.amazonaws.com\n" .
    "x-amz-date:$date\n" .
    "x-amz-security-token:" . $sessionToken . "\n" .
    "x-amz-target:DynamoDB_20111205.$target\n" .
    "\n" .
    $json;

  my $b64 = hmac_sha256_base64(sha256($tosign), $secretAccessKey);
  while (length($b64) % 4) {$b64 .= '=';}

  ##Dynamo request
  my $string =
    "POST http://dynamodb.us-east-1.amazonaws.com/ HTTP/1.1\n" .
    "host: dynamodb.us-east-1.amazonaws.com\n" .
    "x-amz-date: $date\n" .
    "x-amzn-authorization: AWS3 AWSAccessKeyId=" . $accessKeyId . ",Algorithm=HmacSHA256,SignedHeaders=host;x-amz-date;x-amz-security-token;x-amz-target,Signature=$b64\n" .
    "x-amz-target: DynamoDB_20111205.$target\n" .
    "x-amz-security-token: " . $sessionToken . "\n" .
    "content-type: application/x-amz-json-1.0\n" .
    "connection: Keep-Alive\n" .
    "user-agent: perl\n" .
    "\n" .
    $json;

  my $req = HTTP::Request->parse($string);

  my $ua  = LWP::UserAgent->new;

  print Dumper($ua->request($req));
}
于 2012-01-30T22:30:47.227 回答