-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathindex.js
78 lines (66 loc) · 1.7 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
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
const util = require('util');
class UpdateCacheEnv {
constructor(serverless, options) {
this.options = options;
this.serverless = serverless;
this.provider = this.serverless.getProvider('aws');
this.awsInfo = this.serverless
.pluginManager
.plugins
.find(p => p.constructor.name === 'AwsInfo');
this.bucketCache = this.serverless
.service
.provider
.environment
.bucketCache;
this.registry = this.serverless
.service
.provider
.environment
.registry;
this.cacheEnabled = this.serverless
.service
.provider
.environment
.cacheEnabled;
this.hooks = {
'after:deploy:deploy': this.afterDeploy.bind(this),
};
}
afterDeploy() {
const lambda = new this.provider.sdk.Lambda({
signatureVersion: 'v4',
region: this.options.region,
});
const cacheFunction = this
.awsInfo
.gatheredData
.info
.functions
.find(f => f.name === 'cache');
if (!cacheFunction) {
throw new Error('Cache function has not been deployed correctly to AWS.');
}
const params = {
FunctionName: cacheFunction.deployedName,
Environment: {
Variables: {
apiEndpoint: `${this.awsInfo.gatheredData.info.endpoint}/registry`,
region: this.options.region,
bucketCache: this.bucketCache,
registry: this.registry,
cacheEnabled: this.cacheEnabled,
}
},
};
lambda
.updateFunctionConfiguration(params)
.promise()
.then(() => {
this.serverless.cli.log('AWS Cache Environment Ready.');
}).catch(err => {
this.serverless.cli.log(err.message);
});
}
}
module.exports = UpdateCacheEnv;