From aaa1ef6fdc0ccf0f620bc09f6e2621e18c09eb18 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Tue, 4 Oct 2016 15:27:15 -0700 Subject: [PATCH] Remove non-alphanumeric characters in resource logical ids --- .../aws/deploy/compile/events/stream/index.js | 5 +++-- .../compile/events/stream/tests/index.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/plugins/aws/deploy/compile/events/stream/index.js b/lib/plugins/aws/deploy/compile/events/stream/index.js index 2b824e506..861103da5 100644 --- a/lib/plugins/aws/deploy/compile/events/stream/index.js +++ b/lib/plugins/aws/deploy/compile/events/stream/index.js @@ -82,9 +82,10 @@ class AwsCompileStreamEvents { const streamType = EventSourceArn.split(':')[2]; const normalizedStreamType = streamType[0].toUpperCase() + streamType.substr(1); - // get the name of the stream + // get the name of the stream (and remove any non-alphanumerics in it) const streamName = EventSourceArn.split('/')[1]; - const normalizedStreamName = streamName[0].toUpperCase() + streamName.substr(1); + const normalizedStreamName = streamName[0].toUpperCase() + + streamName.substr(1).replace(/\W/g, ''); // create type specific PolicyDocument statements let streamStatement = {}; diff --git a/lib/plugins/aws/deploy/compile/events/stream/tests/index.js b/lib/plugins/aws/deploy/compile/events/stream/tests/index.js index a90881516..0dcabb175 100644 --- a/lib/plugins/aws/deploy/compile/events/stream/tests/index.js +++ b/lib/plugins/aws/deploy/compile/events/stream/tests/index.js @@ -403,5 +403,23 @@ describe('AwsCompileStreamEvents', () => { .PolicyDocument.Statement.length ).to.equal(0); }); + + it('should remove all non-alphanumerics from stream names for the resource logical ids', () => { + awsCompileStreamEvents.serverless.service.functions = { + first: { + events: [ + { + stream: 'arn:aws:kinesis:region:account:stream/some-long-name', + }, + ], + }, + }; + + awsCompileStreamEvents.compileStreamEvents(); + + expect(awsCompileStreamEvents.serverless.service + .provider.compiledCloudFormationTemplate.Resources + ).to.have.any.keys('FirstEventSourceMappingKinesisSomelongname'); + }); }); });