Amazon-DynamoDB
view release on metacpan or search on metacpan
lib/Amazon/DynamoDB/20120810.pm view on Meta::CPAN
package Amazon::DynamoDB::20120810;
$Amazon::DynamoDB::20120810::VERSION = '0.35';
use strict;
use warnings;
use Future;
use Future::Utils qw(repeat try_repeat);
use POSIX qw(strftime);
use JSON::MaybeXS qw(decode_json encode_json);
use MIME::Base64;
use List::Util;
use List::MoreUtils;
use B qw(svref_2object);
use HTTP::Request;
use Kavorka;
use Amazon::DynamoDB::Types;
use Type::Registry;
use VM::EC2::Security::CredentialCache;
use AWS::Signature4;
BEGIN {
my $reg = "Type::Registry"->for_me;
$reg->add_types(-Standard);
$reg->add_types("Amazon::DynamoDB::Types");
};
sub new {
my $class = shift;
bless { @_ }, $class
}
sub implementation { shift->{implementation} }
sub host { shift->{host} }
sub port { shift->{port} }
sub ssl { shift->{ssl} }
sub algorithm { 'AWS4-HMAC-SHA256' }
sub scope { shift->{scope} }
sub access_key { shift->{access_key} }
sub secret_key { shift->{secret_key} }
sub debug_failures { shift->{debug} }
sub max_retries { shift->{max_retries} }
method create_table(TableNameType :$TableName!,
Int :$ReadCapacityUnits = 2,
Int :$WriteCapacityUnits = 2,
AttributeDefinitionsType :$AttributeDefinitions,
KeySchemaType :$KeySchema!,
ArrayRef[GlobalSecondaryIndexType] :$GlobalSecondaryIndexes where { scalar(@$_) <= 5 },
ArrayRef[LocalSecondaryIndexType] :$LocalSecondaryIndexes
) {
my %payload = (
TableName => $TableName,
ProvisionedThroughput => {
ReadCapacityUnits => int($ReadCapacityUnits),
WriteCapacityUnits => int($WriteCapacityUnits),
}
);
if (defined($AttributeDefinitions)) {
foreach my $field_name (keys %$AttributeDefinitions) {
my $type = $AttributeDefinitions->{$field_name};
push @{$payload{AttributeDefinitions}}, {
AttributeName => $field_name,
AttributeType => $type // 'S',
}
}
}
$payload{KeySchema} = _create_key_schema($KeySchema, $AttributeDefinitions);
foreach my $index_record (['GlobalSecondaryIndexes', $GlobalSecondaryIndexes],
['LocalSecondaryIndexes', $LocalSecondaryIndexes]) {
my $index_type = $index_record->[0];
my $index = $index_record->[1];
if (defined($index)) {
foreach my $i (@$index) {
my $r = {
IndexName => $i->{IndexName},
(($index_type eq 'GlobalSecondaryIndexes') ?
(ProvisionedThroughput => {
ReadCapacityUnits => int($i->{ProvisionedThroughput}->{ReadCapacityUnits} // 1),
WriteCapacityUnits => int($i->{ProvisionedThroughput}->{WriteCapacityUnits} // 1),
( run in 1.295 second using v1.01-cache-2.11-cpan-39bf76dae61 )