From 20a2a48a74cdee043511de6108ae3986ebec7b1d Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Fri, 27 Jan 2017 13:22:27 +0100 Subject: [PATCH 1/2] Remove on-the-fly arn generation for displayed functions --- lib/plugins/aws/info/display.js | 2 +- lib/plugins/aws/info/display.test.js | 9 +++------ lib/plugins/aws/info/getStackInfo.js | 22 +++++++--------------- lib/plugins/aws/info/getStackInfo.test.js | 21 +-------------------- 4 files changed, 12 insertions(+), 42 deletions(-) diff --git a/lib/plugins/aws/info/display.js b/lib/plugins/aws/info/display.js index 1731c5381..13ec671f5 100644 --- a/lib/plugins/aws/info/display.js +++ b/lib/plugins/aws/info/display.js @@ -60,7 +60,7 @@ module.exports = { if (info.functions && info.functions.length > 0) { info.functions.forEach((f) => { - functionsMessage += `\n ${f.name}: ${f.arn}`; + functionsMessage += `\n ${f.name}`; }); } else { functionsMessage += '\n None'; diff --git a/lib/plugins/aws/info/display.test.js b/lib/plugins/aws/info/display.test.js index 709f7a573..3cd003e3d 100644 --- a/lib/plugins/aws/info/display.test.js +++ b/lib/plugins/aws/info/display.test.js @@ -154,15 +154,12 @@ describe('#display()', () => { awsInfo.gatheredData.info.functions = [ { name: 'function1', - arn: 'arn:aws:iam::12345678:function:function1', }, { name: 'function2', - arn: 'arn:aws:iam::12345678:function:function2', }, { name: 'function3', - arn: 'arn:aws:iam::12345678:function:function3', }, ]; @@ -177,9 +174,9 @@ describe('#display()', () => { expectedMessage += `\n${chalk.yellow('endpoints:')}`; expectedMessage += '\n None'; expectedMessage += `\n${chalk.yellow('functions:')}`; - expectedMessage += '\n function1: arn:aws:iam::12345678:function:function1'; - expectedMessage += '\n function2: arn:aws:iam::12345678:function:function2'; - expectedMessage += '\n function3: arn:aws:iam::12345678:function:function3'; + expectedMessage += '\n function1'; + expectedMessage += '\n function2'; + expectedMessage += '\n function3'; const message = awsInfo.display(); expect(consoleLogStub.calledOnce).to.equal(true); diff --git a/lib/plugins/aws/info/getStackInfo.js b/lib/plugins/aws/info/getStackInfo.js index fdc834cff..c7cc83f71 100644 --- a/lib/plugins/aws/info/getStackInfo.js +++ b/lib/plugins/aws/info/getStackInfo.js @@ -36,6 +36,13 @@ module.exports = { // Outputs this.gatheredData.outputs = outputs; + // Functions + this.serverless.service.getAllFunctions().forEach((func) => { + const functionInfo = {}; + functionInfo.name = `${this.serverless.service.service}-${this.options.stage}-${func}`; + this.gatheredData.info.functions.push(functionInfo); + }); + // Endpoints outputs.filter(x => x.OutputKey.match(serviceEndpointOutputRegex)) .forEach(x => { @@ -43,21 +50,6 @@ module.exports = { }); } - return BbPromise.resolve(); - }) - .then(() => this.provider.getAccountId()) - .then((accountId) => { - this.gatheredData.info.functions = []; - - this.serverless.service.getAllFunctions().forEach((func) => { - const functionInfo = {}; - const name = `${this.serverless.service.service}-${this.options.stage}-${func}`; - const arn = `arn:aws:lambda:${this.options.region}:${accountId}:function:${name}`; - functionInfo.name = name; - functionInfo.arn = arn; - this.gatheredData.info.functions.push(functionInfo); - }); - return BbPromise.resolve(); }); }, diff --git a/lib/plugins/aws/info/getStackInfo.test.js b/lib/plugins/aws/info/getStackInfo.test.js index 41ea599f4..90a10718b 100644 --- a/lib/plugins/aws/info/getStackInfo.test.js +++ b/lib/plugins/aws/info/getStackInfo.test.js @@ -11,7 +11,6 @@ describe('#getStackInfo()', () => { let serverless; let awsInfo; let describeStacksStub; - let getAccountIdStub; beforeEach(() => { serverless = new Serverless(); @@ -28,13 +27,10 @@ describe('#getStackInfo()', () => { awsInfo = new AwsInfo(serverless, options); describeStacksStub = sinon.stub(awsInfo.provider, 'request'); - getAccountIdStub = sinon.stub(awsInfo.provider, 'getAccountId') - .returns(BbPromise.resolve(12345678)); }); afterEach(() => { awsInfo.provider.request.restore(); - awsInfo.provider.getAccountId.restore(); }); it('attach info from describeStack call to this.gatheredData if result is available', () => { @@ -79,11 +75,9 @@ describe('#getStackInfo()', () => { info: { functions: [ { - arn: 'arn:aws:lambda:us-east-1:12345678:function:my-service-dev-hello', name: 'my-service-dev-hello', }, { - arn: 'arn:aws:lambda:us-east-1:12345678:function:my-service-dev-world', name: 'my-service-dev-world', }, ], @@ -123,8 +117,6 @@ describe('#getStackInfo()', () => { awsInfo.options.region )).to.equal(true); - expect(getAccountIdStub.calledOnce).to.equal(true); - expect(awsInfo.gatheredData).to.deep.equal(expectedGatheredDataObj); }); }); @@ -136,16 +128,7 @@ describe('#getStackInfo()', () => { const expectedGatheredDataObj = { info: { - functions: [ - { - arn: 'arn:aws:lambda:us-east-1:12345678:function:my-service-dev-hello', - name: 'my-service-dev-hello', - }, - { - arn: 'arn:aws:lambda:us-east-1:12345678:function:my-service-dev-world', - name: 'my-service-dev-world', - }, - ], + functions: [], endpoint: '', service: 'my-service', stage: 'dev', @@ -166,8 +149,6 @@ describe('#getStackInfo()', () => { awsInfo.options.region )).to.equal(true); - expect(getAccountIdStub.calledOnce).to.equal(true); - expect(awsInfo.gatheredData).to.deep.equal(expectedGatheredDataObj); }); }); From 0c16dadd3c3f84000b5627cf252f95a207b6951b Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Fri, 27 Jan 2017 13:27:50 +0100 Subject: [PATCH 2/2] Update info docs --- docs/providers/aws/cli-reference/info.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/providers/aws/cli-reference/info.md b/docs/providers/aws/cli-reference/info.md index 7e71a4eb0..e599b576d 100644 --- a/docs/providers/aws/cli-reference/info.md +++ b/docs/providers/aws/cli-reference/info.md @@ -47,7 +47,7 @@ api keys: endpoints: GET - https://dxaynpuzd4.execute-api.us-east-1.amazonaws.com/dev/users functions: - my-serverless-service-dev-hello: arn:aws:lambda:us-east-1:377024778620:function:my-serverless-service-dev-hello + my-serverless-service-dev-hello ``` #### Verbose @@ -66,14 +66,11 @@ api keys: endpoints: GET - https://dxaynpuzd4.execute-api.us-east-1.amazonaws.com/dev/users functions: - my-serverless-service-dev-hello: arn:aws:lambda:us-east-1:377024778620:function:my-serverless-service-dev-hello + my-serverless-service-dev-hello Stack Outputs CloudFrontUrl: d2d10e2tyk1pei.cloudfront.net -ListScreenshotsLambdaFunctionArn: arn:aws:lambda:us-east-1:377024778620:function:lambda-screenshots-dev-listScreenshots ScreenshotBucket: dev-svdgraaf-screenshots -CreateThumbnailsLambdaFunctionArn: arn:aws:lambda:us-east-1:377024778620:function:lambda-screenshots-dev-createThumbnails -TakeScreenshotLambdaFunctionArn: arn:aws:lambda:us-east-1:377024778620:function:lambda-screenshots-dev-takeScreenshot ServiceEndpoint: https://12341jc801.execute-api.us-east-1.amazonaws.com/dev ServerlessDeploymentBucketName: lambda-screenshots-dev-serverlessdeploymentbucket-15b7pkc04f98a ```