forked from sid88in/serverless-appsync-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-stack-value.js
More file actions
37 lines (34 loc) · 970 Bytes
/
get-stack-value.js
File metadata and controls
37 lines (34 loc) · 970 Bytes
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
function getServerlessStackName(service, provider) {
return `${service.getServiceName()}-${provider.getStage()}`;
}
function getValue(service, provider, value, name) {
if (typeof value === "string") {
return Promise.resolve(value);
} else if (typeof value.Ref === "string") {
return provider
.request(
"CloudFormation",
"listStackResources",
{
StackName: getServerlessStackName(service, provider)
},
provider.getStage(),
provider.getRegion()
)
.then(result => {
const resource = result.StackResourceSummaries.find(
r => r.LogicalResourceId === value.Ref
);
if (!resource) {
throw new Error(`${name}: Ref "${value.Ref} not found`);
}
return resource.PhysicalResourceId;
});
} else {
return Promise.reject(`${value} is not a valid ${name}`);
}
}
module.exports = {
getServerlessStackName,
getValue,
};