lib/plugins/platform/platform.js/Platform/publishService
class Platform:  publishService() {
    if (!this.serverless.service.deployment || !this.serverless.service.deployment.deploymentId) {
      return BbPromise.resolve();
    }
    this.serverless.cli.log('Publishing service to Serverless Platform...');

    return this.provider.getStackResources().then(resources => {
      this.cfResources = resources;
    }).then(() => this.provider.getAccountId())
      .then(accountId => {
        const service = this.serverless.service;

        this.data = {
          app: this.serverless.service.app,
          tenant: this.serverless.service.tenant,
          accessKey: this.serverless.service.deployment.accessKey,
          version: '0.1.0',
          service: this.getServiceData(),
          functions: [],
          subscriptions: [],
          resources: this.getResources(),
        };

        this.data.service.provider.accountId = accountId;

        Object.keys(service.functions).forEach(fn => {
          const fnData = this.getFunctionData(fn);
          this.data.functions.push(fnData);
          this.serverless.service.getAllEventsInFunction(fn).forEach(event => {
            let subscription = {
              functionId: this.serverless.service.getFunction(fn).name,
              details: {},
              provider: this.data.service.provider,
              permissions: {},
            };

            if (Object.keys(event)[0] === 'eventgateway') {
              subscription = this.getEGSubscription(event.eventgateway, fn);
            } else if (Object.keys(event)[0] === 'http') {
              subscription = this.getApigSubscription(event.http, fn);
            } else if (Object.keys(event)[0] === 'stream') {
              if (typeof event.stream === 'string') {
                const streamType = event.stream.split(':')[2];
                subscription.type = `aws.${streamType}`;
              } else if (typeof event.stream === 'object') {
                if (event.stream.type === 'dynamodb') {
                  subscription.type = 'aws.dynamodb';
                } else if (event.stream.type === 'kinesis') {
                  subscription.type = 'aws.kinesis';
                }
              }
              subscription.event = event.stream;
            } else if (Object.keys(event)[0] === 's3') {
              subscription = this.getS3Subscription(event.s3, fn);
            } else if (Object.keys(event)[0] === 'schedule') {
              subscription = this.getScheduledSubscription(event.schedule, fn);
            } else if (Object.keys(event)[0] === 'sns') {
              subscription = this.getSnsSubscription(event.sns, fn);
            } else if (Object.keys(event)[0] === 'alexaSkill') {
              subscription.type = 'aws.alexa.skill';
              subscription.event = event.alexaSkill;
            } else if (Object.keys(event)[0] === 'iot') {
              subscription.type = 'aws.iot';
              subscription.event = event.iot;
            } else if (Object.keys(event)[0] === 'cloudwatchEvent') {
              subscription.type = 'aws.cloudwatch';
              subscription.event = event.cloudwatchEvent;
            } else if (Object.keys(event)[0] === 'cloudwatchLog') {
              subscription.type = 'aws.cloudwatch.log';
              subscription.event = event.cloudwatchLog;
            } else if (Object.keys(event)[0] === 'cognitoUserPool') {
              subscription.type = 'aws.cognito';
              subscription.event = event.cognitoUserPool;
            } else if (Object.keys(event)[0] === 'alexaSmartHome') {
              subscription.type = 'aws.alexa.home';
              subscription.event = event.alexaSmartHome;
            }

            subscription.subscriptionId = crypto.createHash('md5')
              .update(JSON.stringify(subscription)).digest('hex');

            // dashboard currently does not support sqs
            if (Object.keys(event)[0] !== 'sqs') {
              this.data.subscriptions.push(subscription);
            }
          });
        });

        const deploymentData = this.serverless.service.deployment;
        deploymentData.status = 'Success';
        deploymentData.state = this.data;

        return platform.updateDeployment(deploymentData)
          .then(() => {
            const trackingData = {
              tenant: deploymentData.tenant,
              app: deploymentData.app,
            };
            userStats.track('service_published', trackingData);
            const serviceUrlData = {
              tenant: deploymentData.tenant,
              app: deploymentData.app,
              name: deploymentData.state.service.name,
            };
            const serviceUrl = platform.getServiceUrl(serviceUrlData);
            this.serverless.cli
              .log('Successfully published your service on the Serverless Platform');
            this.serverless.cli.log(`Service URL:  ${serviceUrl}`);
          });
      });
  }