1 | var AWS = require('aws-sdk');
|
2 | var utils = require('../lib/utils');
|
3 | var Response = require('../lib/response');
|
4 |
|
5 | module.exports = DynamoDBStreamLabel;
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function DynamoDBStreamLabel(tableName, tableRegion) {
|
14 | if (!tableName)
|
15 | throw new Error('Missing Parameter TableName');
|
16 | if (!tableRegion)
|
17 | throw new Error('Missing Parameter TableRegion');
|
18 |
|
19 | this.dynamodb = new AWS.DynamoDB({ region: tableRegion });
|
20 | this.tableName = tableName;
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | DynamoDBStreamLabel.manage = function(event, context) {
|
43 | if (!utils.validCloudFormationEvent(event))
|
44 | return context.done(null, 'ERROR: Invalid CloudFormation event');
|
45 |
|
46 | var response = new Response(event, context);
|
47 |
|
48 | var requestType = event.RequestType.toLowerCase();
|
49 | var stream;
|
50 | try {
|
51 | stream = new DynamoDBStreamLabel(
|
52 | event.ResourceProperties.TableName,
|
53 | event.ResourceProperties.TableRegion
|
54 | );
|
55 | } catch(err) {
|
56 | return response.send(err);
|
57 | }
|
58 |
|
59 | stream[requestType](function(err, label) {
|
60 | if (label) response.setId(label);
|
61 | response.send(err);
|
62 | });
|
63 | };
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | DynamoDBStreamLabel.prototype.create = function(callback) {
|
71 | this.dynamodb.describeTable({ TableName: this.tableName }, function(err, data) {
|
72 | if (err) return callback(err);
|
73 |
|
74 | var label = data.Table.LatestStreamLabel;
|
75 | if (!label) return callback(new Error('Table is not stream enabled'));
|
76 |
|
77 | callback(null, label);
|
78 | });
|
79 | };
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | DynamoDBStreamLabel.prototype.update = function(callback) {
|
87 | this.create(callback);
|
88 | };
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | DynamoDBStreamLabel.prototype.delete = function(callback) {
|
96 | callback();
|
97 | };
|