Skip to content

Commit 00a5afe

Browse files
author
Frank Schmid
committed
Issue #2 Prepare APIG info output
There is an issue with the APIGateway::getDeployment() REST API function. According to the documentation it should return the API layout, but it does not.
1 parent be4155d commit 00a5afe

File tree

1 file changed

+60
-5
lines changed

1 file changed

+60
-5
lines changed

lib/listAliases.js

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,42 @@ const BbPromise = require('bluebird');
77
const _ = require('lodash');
88
const chalk = require('chalk');
99

10+
/* eslint no-console: "off" */
11+
1012
module.exports = {
1113

14+
listDescribeApiStage(apiId, stageName) {
15+
16+
if (!apiId) {
17+
return BbPromise.resolve(null);
18+
}
19+
20+
return this._provider.request('APIGateway',
21+
'getStage',
22+
{
23+
restApiId: apiId,
24+
stageName: stageName
25+
},
26+
this._options.stage,
27+
this._options.region)
28+
.then(stage => {
29+
return this._provider.request('APIGateway',
30+
'getDeployment',
31+
{
32+
restApiId: apiId,
33+
deploymentId: stage.deploymentId
34+
},
35+
this._options.stage,
36+
this._options.region);
37+
})
38+
.catch(err => {
39+
if (/^Invalid stage/.test(err.message)) {
40+
return BbPromise.resolve(null);
41+
}
42+
return BbPromise.reject(err);
43+
});
44+
},
45+
1246
listDescribeStack(stackName) {
1347

1448
return this._provider.request('CloudFormation',
@@ -18,24 +52,41 @@ module.exports = {
1852
this._options.region);
1953
},
2054

55+
listGetApiId(stackName) {
56+
57+
return this._provider.request('CloudFormation',
58+
'describeStackResource',
59+
{
60+
LogicalResourceId: 'ApiGatewayRestApi',
61+
StackName: stackName
62+
},
63+
this._options.stage,
64+
this._options.region)
65+
.then(cfData => cfData.StackResourceDetail.PhysicalResourceId)
66+
.catch(() => BbPromise.resolve(null));
67+
},
68+
2169
listAliases() {
2270

2371
console.log(chalk.yellow('aliases:'));
2472

2573
return BbPromise.join(
26-
BbPromise.bind(this).then(this.aliasStackLoadCurrentTemplate),
27-
BbPromise.bind(this).then(this.aliasStackLoadAliasTemplates)
74+
BbPromise.bind(this).then(this.aliasStackLoadAliasTemplates),
75+
this.listGetApiId(this._provider.naming.getStackName())
2876
)
29-
.spread((currentTemplate, aliasStackTemplates) => {
77+
.spread((aliasStackTemplates, apiId) => {
3078
return BbPromise.mapSeries(aliasStackTemplates, aliasTemplate => {
3179

3280
const aliasName = _.get(aliasTemplate, 'Outputs.ServerlessAliasName.Value');
3381
if (aliasName) {
3482
console.log(chalk.white(` ${aliasName}`));
3583

3684
if (this._options.verbose) {
37-
return this.listDescribeStack(`${this._provider.naming.getStackName()}-${aliasName}`)
38-
.then(resources => {
85+
return BbPromise.join(
86+
this.listDescribeStack(`${this._provider.naming.getStackName()}-${aliasName}`),
87+
this.listDescribeApiStage(apiId, aliasName)
88+
)
89+
.spread((resources /*, apiStage */) => {
3990
const versions = _.filter(resources.StackResources, [ 'ResourceType', 'AWS::Lambda::Version' ]);
4091

4192
console.log(chalk.white(' Functions:'));
@@ -44,6 +95,10 @@ module.exports = {
4495
const functionVersion = _.last(version.PhysicalResourceId.split(':'));
4596

4697
console.log(chalk.yellow(` ${functionName} -> ${functionVersion}`));
98+
99+
// Print deployed endpoints for the function
100+
// FIXME: Check why APIG getStage and getDeployment do not return the stage API layout.
101+
47102
});
48103

49104
return BbPromise.resolve();

0 commit comments

Comments
 (0)