1 | var AWS = require('aws-sdk');
|
2 | var utils = require('../lib/utils');
|
3 | var Response = require('../lib/response');
|
4 |
|
5 | module.exports = StackOutputs;
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function StackOutputs(stackName, region) {
|
13 | if (!stackName)
|
14 | throw new Error('Missing Parameter StackName');
|
15 | if (!region)
|
16 | throw new Error('Missing Parameter Region');
|
17 |
|
18 | this.stackName = stackName;
|
19 | this.region = region;
|
20 | this.cfn = new AWS.CloudFormation({ region: region });
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | StackOutputs.manage = function(event, context) {
|
42 | if (!utils.validCloudFormationEvent(event))
|
43 | return context.done(null, 'ERROR: Invalid CloudFormation event');
|
44 |
|
45 | var response = new Response(event, context);
|
46 |
|
47 | var requestType = event.RequestType.toLowerCase();
|
48 | var message;
|
49 | try {
|
50 | message = new StackOutputs(
|
51 | event.ResourceProperties.StackName,
|
52 | event.ResourceProperties.Region
|
53 | );
|
54 | } catch (err) {
|
55 | return response.send(err);
|
56 | }
|
57 |
|
58 | message[requestType](function(err, data) {
|
59 | response.send(err, data);
|
60 | });
|
61 | };
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | StackOutputs.prototype.create = function(callback) {
|
68 | var params = { StackName: this.stackName };
|
69 | var stackName = this.stackName;
|
70 | var region = this.region;
|
71 |
|
72 | this.cfn.describeStacks(params, function(err, data) {
|
73 | if (err) return callback(err);
|
74 | if (!data.Stacks[0]) return callback(new Error('No stack named %s was found in %s'), stackName, region);
|
75 |
|
76 | var outputs = data.Stacks[0].Outputs.reduce(function(outputs, o) {
|
77 | outputs[o.OutputKey] = o.OutputValue;
|
78 | return outputs;
|
79 | }, {});
|
80 |
|
81 | callback(null, outputs);
|
82 | });
|
83 | };
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | StackOutputs.prototype.update = StackOutputs.prototype.create;
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | StackOutputs.prototype.delete = function(callback) {
|
96 | callback();
|
97 | };
|