This repository has been archived by the owner on Jun 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
awssum-amazon-dynamodb.js
132 lines (102 loc) · 4.25 KB
/
awssum-amazon-dynamodb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// --------------------------------------------------------------------------------------------------------------------
//
// dynamodb.js - class for AWS DynamoDB
//
// Copyright (c) 2012 AppsAttic Ltd - http://www.appsattic.com/
// Written by Andrew Chilton <[email protected]>
//
// License: http://opensource.org/licenses/MIT
//
// --------------------------------------------------------------------------------------------------------------------
// requires
// built-ins
var util = require('util');
var crypto = require('crypto');
// dependencies
var _ = require('underscore');
var dateFormat = require('dateformat');
// our own
var awssum = require('awssum');
var amazon = require('awssum-amazon');
var Sts = require('awssum-amazon-sts').Sts;
var operations = require('./config.js');
// --------------------------------------------------------------------------------------------------------------------
// package variables
var MARK = 'dynamodb: ';
// From: http://docs.amazonwebservices.com/general/latest/gr/rande.html
var endPoint = {};
endPoint[amazon.US_EAST_1] = "dynamodb.us-east-1.amazonaws.com";
endPoint[amazon.US_WEST_1] = "dynamodb.us-west-1.amazonaws.com";
endPoint[amazon.US_WEST_2] = "dynamodb.us-west-2.amazonaws.com";
endPoint[amazon.EU_WEST_1] = "dynamodb.eu-west-1.amazonaws.com";
endPoint[amazon.AP_SOUTHEAST_1] = "dynamodb.ap-southeast-1.amazonaws.com";
endPoint[amazon.AP_SOUTHEAST_2] = "dynamodb.ap-southeast-2.amazonaws.com";
endPoint[amazon.AP_NORTHEAST_1] = "dynamodb.ap-northeast-1.amazonaws.com";
endPoint[amazon.SA_EAST_1] = "dynamodb.sa-east-1.amazonaws.com";
endPoint[amazon.US_GOV_WEST_1] = "dynamodb.us-gov-west-1.amazonaws.com";
var version = '20111205';
// --------------------------------------------------------------------------------------------------------------------
// constructor
var DynamoDB = function(opts) {
var self = this;
// call the superclass for initialisation
DynamoDB.super_.call(this, opts);
// check the region is valid
if ( ! endPoint[opts.region] ) {
throw MARK + "invalid region '" + opts.region + "'";
}
// create an STS client to use for getting the session tokens
self._sts = new Sts(opts);
return self;
};
// inherit from Amazon
util.inherits(DynamoDB, amazon.AmazonSignatureV4);
// --------------------------------------------------------------------------------------------------------------------
// methods we need to implement from amazon.js
DynamoDB.prototype.method = function() {
return 'POST';
};
DynamoDB.prototype.host = function(args) {
return endPoint[this.region()];
};
DynamoDB.prototype.version = function() {
return version;
};
DynamoDB.prototype.extractBody = function() {
// DynamoDB always returns JSON
return 'json';
};
// ----------------------------------------------------------------------------
// AWS Signature v4
DynamoDB.prototype.scope = function() {
return 'dynamodb';
};
DynamoDB.prototype.serviceName = function() {
return 'DynamoDB';
};
DynamoDB.prototype.needsTarget = function() {
return true;
};
// This service uses the AWS Signature v4.
// Hopefully, it fulfills : http://docs.amazonwebservices.com/cloudsearch/latest/developerguide/requestauth.html
DynamoDB.prototype.contentType = function() {
return 'application/x-amz-json-1.0';
};
// --------------------------------------------------------------------------------------------------------------------
// operations on the service
_.each(operations, function(operation, operationName) {
DynamoDB.prototype[operationName] = awssum.makeOperation(operation);
});
// --------------------------------------------------------------------------------------------------------------------
// exports
exports.US_EAST_1 = amazon.US_EAST_1;
exports.US_WEST_1 = amazon.US_WEST_1;
exports.US_WEST_2 = amazon.US_WEST_2;
exports.EU_WEST_1 = amazon.EU_WEST_1;
exports.AP_SOUTHEAST_1 = amazon.AP_SOUTHEAST_1;
exports.AP_SOUTHEAST_2 = amazon.AP_SOUTHEAST_2;
exports.AP_NORTHEAST_1 = amazon.AP_NORTHEAST_1;
exports.SA_EAST_1 = amazon.SA_EAST_1;
exports.US_GOV_WEST = amazon.US_GOV_WEST;
exports.DynamoDB = DynamoDB;
// --------------------------------------------------------------------------------------------------------------------