forked from sid88in/serverless-appsync-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-stack-value.js
33 lines (29 loc) · 904 Bytes
/
get-stack-value.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
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 (value && typeof value.Ref === 'string') {
return provider
.request(
'CloudFormation',
'listStackResources',
{
StackName: getServerlessStackName(service, provider),
},
)
.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;
});
}
return Promise.reject(new Error(`${value} is not a valid ${name}`));
}
module.exports = {
getServerlessStackName,
getValue,
};