Remove non-alphanumeric characters in resource logical ids

This commit is contained in:
Philipp Muens 2016-10-04 15:27:15 -07:00
parent d8859bf157
commit aaa1ef6fdc
2 changed files with 21 additions and 2 deletions

View File

@ -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 = {};

View File

@ -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');
});
});
});