Skip to content

Instantly share code, notes, and snippets.

@ac360
Last active October 12, 2018 14:10
Show Gist options
  • Save ac360/8e6f1a6bb18c64ab8016e465af5973e3 to your computer and use it in GitHub Desktop.
Save ac360/8e6f1a6bb18c64ab8016e465af5973e3 to your computer and use it in GitHub Desktop.
Serverless Framework V.2 - Info Experience

Info Experience

info() is a Component method that returns an javascript object that contains a summary of information about that component that is intended to easily communicate its most important information to humans, while :

const summary = componentInstance.info()

// { name: foo }

You can call it via the CLI as well:

$ serverless info

ServiceInstance - Service
|
|_ componentInstance - Component
     name: foo

In the CLI context, when you call $ serverless deploy on an App, Service or Component type, the info() method is automatically called immediately after everything has been successfully deployed on the App or Service or Component type, as well as its top-level component dependencies.

When you deploy a Service, info() is called on the Service as well as each top-level components. When you deploy an App, info() is first called on the App and its top-level component dependencies, then we loop through each of the App's Services and call info() on them and their top-level components.

Here is what the output should look like when an App is deployed:

$ serverless deploy

WebApp - App
|
|_ restApi - RestApi
     domain: https://execute-api.amazonaws.com/
     routes:
       /users:
         post: https://execute-api.amazonaws.com/users
       /users/{id}:
         get:  https://execute-api.amazonaws.com/users/{id}
         delete:  https://execute-api.amazonaws.com/users/{id}
       
WebClient - Service
|
|_ userCreate - Function
|    compute: AwsLambda
|    name: myapp-dev-user-create
|
|_ webClient - AWSS3Website
     domain: https://ajf891-s3bucket.amazonaws.com

In the CLI context, when the Framework calls info() and gets an object, it should use the object's property hierarchy to indicate indentation in the CLI experience.

{
  routes:
    users:
      post: https://execute-api.amazonaws.com/users
}

Looks like this in the CLI:

WebApp - App
|
|_ restApi - RestApi
     domain: https://execute-api.amazonaws.com/
     routes:
       /users:
         post: https://execute-api.amazonaws.com/users

In the CLI context, Component Relationships are indicated by (light grey) lines and use whitespace to make things easy to read. Remember, $ serverless info is for humans and readability is of the upmost importance. Remember, keep it minimal.

When there is no info() command available, simple show the title of the Component:

$ serverless deploy

WebClient - Service
|
|_ myRole - AwsIam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment