-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
45 lines (38 loc) · 1.2 KB
/
index.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
'use strict';
const _ = require("lodash");
class ExportEnvWsgi {
constructor(serverless, options) {
this.serverless = serverless;
this.hooks = {
"before:wsgi:serve:serve": this.initEnv.bind(this)
};
}
initEnv() {
const AWS = this.serverless.providers.aws;
return AWS.request("CloudFormation", "describeStacks", {
StackName: AWS.naming.getStackName()
})
.then((response) => {
const stack = response.Stacks[0];
_.each(this.serverless.service.provider.environment, (value, key) => {
const output = _.find(stack.Outputs, {
'OutputKey': key
});
if (output) {
this.serverless.service.provider.environment[output.OutputKey] = output.OutputValue;
}
});
_.each(this.serverless.service.functions, (func, func_key) => {
_.each(func.environment, (func_env_value, func_env_key) => {
const output = _.find(stack.Outputs, {
'OutputKey': func_env_key
});
if (output) {
func.environment[output.OutputKey] = output.OutputValue;
}
});
});
});
}
}
module.exports = ExportEnvWsgi;