@@ -7,8 +7,42 @@ const BbPromise = require('bluebird');
7
7
const _ = require ( 'lodash' ) ;
8
8
const chalk = require ( 'chalk' ) ;
9
9
10
+ /* eslint no-console: "off" */
11
+
10
12
module . exports = {
11
13
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 ( / ^ I n v a l i d s t a g e / . test ( err . message ) ) {
40
+ return BbPromise . resolve ( null ) ;
41
+ }
42
+ return BbPromise . reject ( err ) ;
43
+ } ) ;
44
+ } ,
45
+
12
46
listDescribeStack ( stackName ) {
13
47
14
48
return this . _provider . request ( 'CloudFormation' ,
@@ -18,24 +52,41 @@ module.exports = {
18
52
this . _options . region ) ;
19
53
} ,
20
54
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
+
21
69
listAliases ( ) {
22
70
23
71
console . log ( chalk . yellow ( 'aliases:' ) ) ;
24
72
25
73
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 ( ) )
28
76
)
29
- . spread ( ( currentTemplate , aliasStackTemplates ) => {
77
+ . spread ( ( aliasStackTemplates , apiId ) => {
30
78
return BbPromise . mapSeries ( aliasStackTemplates , aliasTemplate => {
31
79
32
80
const aliasName = _ . get ( aliasTemplate , 'Outputs.ServerlessAliasName.Value' ) ;
33
81
if ( aliasName ) {
34
82
console . log ( chalk . white ( ` ${ aliasName } ` ) ) ;
35
83
36
84
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 */ ) => {
39
90
const versions = _ . filter ( resources . StackResources , [ 'ResourceType' , 'AWS::Lambda::Version' ] ) ;
40
91
41
92
console . log ( chalk . white ( ' Functions:' ) ) ;
@@ -44,6 +95,10 @@ module.exports = {
44
95
const functionVersion = _ . last ( version . PhysicalResourceId . split ( ':' ) ) ;
45
96
46
97
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
+
47
102
} ) ;
48
103
49
104
return BbPromise . resolve ( ) ;
0 commit comments