Repository: serverless/serverless (JavaScript)
Date: 2017-08-14 23:17:58+00:00
Task type: Feature

Issue:
Display Stack Name with `sls info -v`
# This is a Feature Proposal

## Description

It's difficult to configure variables using the [CloudFormation output syntax](https://serverless.com/framework/docs/providers/aws/guide/variables/#reference-cloudformation-outputs) (`${cf:stackName.outputKey}`) as it's unclear where to find the stack name and output key.  I've found it's easiest to find the output key using `sls info -v` and then looking at the Stack Outputs, but you still need to figure out your stack name.

I propose adding the stack name with `sls info -v` and then updating the docs to make it easier to understand this. It should be pretty straightforward to implement but I just wanted to get feedback on display.

Current output of `sls info -v`:

```bash
$ sls info -v
Service Information
service: my-service
stage: prod
region: us-west-2
api keys:
  None
endpoints:
  POST - https://34jfj01jkf.execute-api.us-west-2.amazonaws.com/prod/hello
functions:
  hello: my-service-prod-hello

Stack Outputs
TrackLambdaFunctionQualifiedArn: arn:aws:lambda:us-west-2:123110001234:function:my-service-prod-hello:23
ServiceEndpoint: https://34jfj01jkf.execute-api.us-west-2.amazonaws.com/prod
ServerlessDeploymentBucketName: my-service-prod-serverlessdeploymentbucket-4qhsgfdht2da
```
In the terminal _Service Information_ and _Stack Outputs_ are underlined.

I'm proposing to change `Stack Outputs` to `CloudFormation Stack` with Stack Name and Stack Outputs below it:

```bash
$ sls info -v
Service Information
service: my-service
stage: prod
region: us-west-2
api keys:
  None
endpoints:
  POST - https://34jfj01jkf.execute-api.us-west-2.amazonaws.com/prod/hello
functions:
  hello: my-service-prod-hello

CloudFormation Stack
Stack Name: my-service-prod

Stack Outputs:
  TrackLambdaFunctionQualifiedArn: arn:aws:lambda:us-west-2:123110001234:function:my-service-prod-hello:23
  ServiceEndpoint: https://34jfj01jkf.execute-api.us-west-2.amazonaws.com/prod
  ServerlessDeploymentBucketName: my-service-prod-serverlessdeploymentbucket-4qhsgfdht2da
```

Open to better ideas on display -- I'm not a designer 😄 


Issue discussion:
How about something like this?
Fits in quite nicely with the current output:
<img width="538" alt="screenshot 2017-08-14 16 58 25" src="https://user-images.githubusercontent.com/28390/29261277-09dcfce6-8112-11e7-89ff-0abeec1c7159.png">


Solution patch:
diff --git a/lib/plugins/aws/info/display.js b/lib/plugins/aws/info/display.js
index 0ba36cbf407..10cf9a6b372 100644
--- a/lib/plugins/aws/info/display.js
+++ b/lib/plugins/aws/info/display.js
@@ -11,7 +11,8 @@ module.exports = {
     message += `${chalk.yellow.underline('Service Information')}\n`;
     message += `${chalk.yellow('service:')} ${info.service}\n`;
     message += `${chalk.yellow('stage:')} ${info.stage}\n`;
-    message += `${chalk.yellow('region:')} ${info.region}`;
+    message += `${chalk.yellow('region:')} ${info.region}\n`;
+    message += `${chalk.yellow('stack:')} ${info.stack}`;
 
     this.serverless.cli.consoleLog(message);
     return message;
diff --git a/lib/plugins/aws/info/getStackInfo.js b/lib/plugins/aws/info/getStackInfo.js
index 7c124f80294..74b1a6bfbd9 100644
--- a/lib/plugins/aws/info/getStackInfo.js
+++ b/lib/plugins/aws/info/getStackInfo.js
@@ -12,6 +12,7 @@ module.exports = {
         service: this.serverless.service.service,
         stage: this.options.stage,
         region: this.options.region,
+        stack: this.provider.naming.getStackName(this.options.stage),
       },
       outputs: [],
     };


Test patch:
diff --git a/lib/plugins/aws/info/display.test.js b/lib/plugins/aws/info/display.test.js
index 84f64f58649..22b955c9e0a 100644
--- a/lib/plugins/aws/info/display.test.js
+++ b/lib/plugins/aws/info/display.test.js
@@ -28,6 +28,7 @@ describe('#display()', () => {
         service: 'my-first',
         stage: 'dev',
         region: 'eu-west-1',
+        stack: 'my-first-dev',
         endpoint: null,
         functions: [],
         apiKeys: [],
@@ -46,7 +47,8 @@ describe('#display()', () => {
     expectedMessage += `${chalk.yellow.underline('Service Information')}\n`;
     expectedMessage += `${chalk.yellow('service:')} my-first\n`;
     expectedMessage += `${chalk.yellow('stage:')} dev\n`;
-    expectedMessage += `${chalk.yellow('region:')} eu-west-1`;
+    expectedMessage += `${chalk.yellow('region:')} eu-west-1\n`;
+    expectedMessage += `${chalk.yellow('stack:')} my-first-dev`;
 
     const message = awsInfo.displayServiceInfo();
     expect(consoleLogStub.calledOnce).to.equal(true);
diff --git a/lib/plugins/aws/info/getStackInfo.test.js b/lib/plugins/aws/info/getStackInfo.test.js
index 05f4e1ada81..af95a837efa 100644
--- a/lib/plugins/aws/info/getStackInfo.test.js
+++ b/lib/plugins/aws/info/getStackInfo.test.js
@@ -86,6 +86,7 @@ describe('#getStackInfo()', () => {
         service: 'my-service',
         stage: 'dev',
         region: 'us-east-1',
+        stack: 'my-service-dev',
       },
       outputs: [
         {
@@ -134,6 +135,7 @@ describe('#getStackInfo()', () => {
         service: 'my-service',
         stage: 'dev',
         region: 'us-east-1',
+        stack: 'my-service-dev',
       },
       outputs: [],
     };