-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
45 lines (43 loc) · 1.27 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
/**
* @implements {import('serverless/classes/Plugin')}
*/
class ExportQualifiedArnsPlugin {
/**
*
* @param {import('serverless')} serverless
*/
constructor(serverless) {
this.serverless = serverless;
this.provider = this.serverless.getProvider('aws');
this.hooks = {
'before:aws:package:finalize:mergeCustomProviderResources': async () => {
// For all known functions that have a versionLogicalId: Export a ref to that.
for (const functionName of this.serverless.service.getAllFunctions()) {
const functionObject = this.serverless.service.getFunction(
functionName,
);
if (!functionObject.versionLogicalId) {
// No version for this function configured
continue;
}
const outputName = `${this.provider.naming.getLambdaLogicalId(
functionName,
)}QualifiedArn`;
if (!this.serverless.service.resources.Outputs) {
this.serverless.service.resources.Outputs = {};
}
if (outputName in this.serverless.service.resources.Outputs) {
// Output with this name exist, keep it.
continue;
}
this.serverless.service.resources.Outputs[outputName] = {
Value: {
Ref: functionObject.versionLogicalId,
},
};
}
},
};
}
}
module.exports = ExportQualifiedArnsPlugin;