diff --git a/lib/plugins/aws/info/display.js b/lib/plugins/aws/info/display.js index 9ef78ca9f..893782735 100644 --- a/lib/plugins/aws/info/display.js +++ b/lib/plugins/aws/info/display.js @@ -12,7 +12,15 @@ module.exports = { message += `${chalk.yellow('service:')} ${info.service}\n`; message += `${chalk.yellow('stage:')} ${info.stage}\n`; message += `${chalk.yellow('region:')} ${info.region}\n`; - message += `${chalk.yellow('stack:')} ${info.stack}`; + message += `${chalk.yellow('stack:')} ${info.stack}\n`; + message += `${chalk.yellow('resources:')} ${info.resourceCount}`; + + if (info.resourceCount >= 150) { + message += `\n${chalk.red('WARNING:')}\n`; + message += ` You have ${info.resourceCount} resources in your service.\n`; + message += ' CloudFormation has a hard limit of 200 resources in a service.\n'; + message += ' For advice on avoiding this limit, check out this link: http://bit.ly/2IiYB38.'; + } this.serverless.cli.consoleLog(message); return message; diff --git a/lib/plugins/aws/info/display.test.js b/lib/plugins/aws/info/display.test.js index a90eed546..df56bd266 100644 --- a/lib/plugins/aws/info/display.test.js +++ b/lib/plugins/aws/info/display.test.js @@ -32,6 +32,7 @@ describe('#display()', () => { endpoint: null, functions: [], apiKeys: [], + resourceCount: 10, }, }; consoleLogStub = sinon.stub(serverless.cli, 'consoleLog').returns(); @@ -48,7 +49,8 @@ describe('#display()', () => { expectedMessage += `${chalk.yellow('service:')} my-first\n`; expectedMessage += `${chalk.yellow('stage:')} dev\n`; expectedMessage += `${chalk.yellow('region:')} eu-west-1\n`; - expectedMessage += `${chalk.yellow('stack:')} my-first-dev`; + expectedMessage += `${chalk.yellow('stack:')} my-first-dev\n`; + expectedMessage += `${chalk.yellow('resources:')} 10`; const message = awsInfo.displayServiceInfo(); expect(consoleLogStub.calledOnce).to.equal(true); diff --git a/lib/plugins/aws/info/getResourceCount.js b/lib/plugins/aws/info/getResourceCount.js new file mode 100644 index 000000000..34e51fda2 --- /dev/null +++ b/lib/plugins/aws/info/getResourceCount.js @@ -0,0 +1,19 @@ +'use strict'; + +const BbPromise = require('bluebird'); + +module.exports = { + getResourceCount() { + const stackName = this.provider.naming.getStackName(); + + return this.provider.request('CloudFormation', + 'listStackResources', + { StackName: stackName }) + .then((result) => { + if (result) { + this.gatheredData.info.resourceCount = result.StackResourceSummaries.length; + } + return BbPromise.resolve(); + }); + }, +}; diff --git a/lib/plugins/aws/info/index.js b/lib/plugins/aws/info/index.js index ebad3db23..ddeface38 100644 --- a/lib/plugins/aws/info/index.js +++ b/lib/plugins/aws/info/index.js @@ -3,6 +3,7 @@ const BbPromise = require('bluebird'); const validate = require('../lib/validate'); const getStackInfo = require('./getStackInfo'); +const getResourceCount = require('./getResourceCount'); const getApiKeyValues = require('./getApiKeyValues'); const display = require('./display'); @@ -15,6 +16,7 @@ class AwsInfo { this, validate, getStackInfo, + getResourceCount, getApiKeyValues, display ); @@ -54,6 +56,7 @@ class AwsInfo { 'aws:info:gatherData': () => BbPromise.bind(this) .then(this.getStackInfo) + .then(this.getResourceCount) .then(this.getApiKeyValues), 'aws:info:displayServiceInfo': () => BbPromise.bind(this)